fix: many bug, add: go back to last pos

This commit is contained in:
starnakin 2023-05-15 20:26:00 +02:00
parent 5fa1d01808
commit bddd7d7074

27
main.py
View File

@ -7,6 +7,7 @@ import sys
import subprocess
from operator import itemgetter
from urllib.parse import unquote
from tinydb.operations import set
def get_files(url: str) -> []:
if (url in ["/../", "../"]):
@ -52,14 +53,14 @@ def preview(filename: str) -> str:
def files_navigator():
global url
path = cookies.get("path")
path = cookies_table.get(query.id == "0").get("last_path")
if (path):
url + path
url = url + path
else:
path = "/"
url = url + "/"
while True:
cookies.update({"last_path": path})
db.update({"last_path", path})
cookies_table.update(set("last_path", get_uri(url)), query.id == "0")
files = get_files(url)
terminal_menu = TerminalMenu(get(files, "name"), preview_command=preview, preview_size=0.3, show_search_hint=True, title=get_uri(url))
file_choose = terminal_menu.show()
@ -79,7 +80,7 @@ def add_site():
site.update({"url": input("url:")})
site.update({"user": input("user(leave blank):")})
site.update({"password": input("password(leave blank):")})
site.update({"id": len(sites_table.all)})
site.update({"id": len(sites_table.all())})
name = input("name[url] :")
if (name == ""):
name = site.get("url")
@ -89,7 +90,8 @@ def add_site():
def set_url(site):
global url
cookies.update({"last_site": site})
cookies_table.update(set("last_site", site.get("id")), query.id == "0")
if (site.get("user") and site.get("password")):
url = f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}/"
else:
@ -98,9 +100,10 @@ def set_url(site):
def sites_navigator():
if (len(sites_table.all()) == 0):
add_site()
site = cookies.get("last_site")
if (site):
set_url(site)
last_site_id = cookies_table.get(query.id == "0").get("last_site")
last_site = sites_table.get(query.id == last_site_id)
if (last_site != None):
set_url(last_site)
files_navigator()
while True:
terminal_menu = TerminalMenu(get(sites_table.all(), "name") + ["", "add", "edit", "remove"], skip_empty_entries=True, show_search_hint=True)
@ -113,7 +116,6 @@ def sites_navigator():
pass
else:
set_url(sites_table.all()[choose])
db.update({"last_path", get_uri(url)})
files_navigator()
db = TinyDB("./database.json", indent=4)
@ -122,6 +124,5 @@ query = Query()
sites_table = db.table("sites")
cookies_table = db.table("cookies")
if (len(cookies_table.all()) == 0):
cookies_table.insert({"id": 0})
cookies = cookies_table.all()[0]
cookies_table.insert({"last_path": "", "last_site": "", "id": "0"})
sites_navigator();