fix: many bug, add: go back to last pos
This commit is contained in:
parent
5fa1d01808
commit
bddd7d7074
27
main.py
27
main.py
@ -7,6 +7,7 @@ import sys
|
|||||||
import subprocess
|
import subprocess
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
from tinydb.operations import set
|
||||||
|
|
||||||
def get_files(url: str) -> []:
|
def get_files(url: str) -> []:
|
||||||
if (url in ["/../", "../"]):
|
if (url in ["/../", "../"]):
|
||||||
@ -52,14 +53,14 @@ def preview(filename: str) -> str:
|
|||||||
|
|
||||||
def files_navigator():
|
def files_navigator():
|
||||||
global url
|
global url
|
||||||
path = cookies.get("path")
|
|
||||||
|
path = cookies_table.get(query.id == "0").get("last_path")
|
||||||
if (path):
|
if (path):
|
||||||
url + path
|
url = url + path
|
||||||
else:
|
else:
|
||||||
path = "/"
|
url = url + "/"
|
||||||
while True:
|
while True:
|
||||||
cookies.update({"last_path": path})
|
cookies_table.update(set("last_path", get_uri(url)), query.id == "0")
|
||||||
db.update({"last_path", path})
|
|
||||||
files = get_files(url)
|
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))
|
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()
|
file_choose = terminal_menu.show()
|
||||||
@ -79,7 +80,7 @@ def add_site():
|
|||||||
site.update({"url": input("url:")})
|
site.update({"url": input("url:")})
|
||||||
site.update({"user": input("user(leave blank):")})
|
site.update({"user": input("user(leave blank):")})
|
||||||
site.update({"password": input("password(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] :")
|
name = input("name[url] :")
|
||||||
if (name == ""):
|
if (name == ""):
|
||||||
name = site.get("url")
|
name = site.get("url")
|
||||||
@ -89,7 +90,8 @@ def add_site():
|
|||||||
def set_url(site):
|
def set_url(site):
|
||||||
global url
|
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")):
|
if (site.get("user") and site.get("password")):
|
||||||
url = f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}/"
|
url = f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}/"
|
||||||
else:
|
else:
|
||||||
@ -98,9 +100,10 @@ def set_url(site):
|
|||||||
def sites_navigator():
|
def sites_navigator():
|
||||||
if (len(sites_table.all()) == 0):
|
if (len(sites_table.all()) == 0):
|
||||||
add_site()
|
add_site()
|
||||||
site = cookies.get("last_site")
|
last_site_id = cookies_table.get(query.id == "0").get("last_site")
|
||||||
if (site):
|
last_site = sites_table.get(query.id == last_site_id)
|
||||||
set_url(site)
|
if (last_site != None):
|
||||||
|
set_url(last_site)
|
||||||
files_navigator()
|
files_navigator()
|
||||||
while True:
|
while True:
|
||||||
terminal_menu = TerminalMenu(get(sites_table.all(), "name") + ["", "add", "edit", "remove"], skip_empty_entries=True, show_search_hint=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
|
pass
|
||||||
else:
|
else:
|
||||||
set_url(sites_table.all()[choose])
|
set_url(sites_table.all()[choose])
|
||||||
db.update({"last_path", get_uri(url)})
|
|
||||||
files_navigator()
|
files_navigator()
|
||||||
|
|
||||||
db = TinyDB("./database.json", indent=4)
|
db = TinyDB("./database.json", indent=4)
|
||||||
@ -122,6 +124,5 @@ query = Query()
|
|||||||
sites_table = db.table("sites")
|
sites_table = db.table("sites")
|
||||||
cookies_table = db.table("cookies")
|
cookies_table = db.table("cookies")
|
||||||
if (len(cookies_table.all()) == 0):
|
if (len(cookies_table.all()) == 0):
|
||||||
cookies_table.insert({"id": 0})
|
cookies_table.insert({"last_path": "", "last_site": "", "id": "0"})
|
||||||
cookies = cookies_table.all()[0]
|
|
||||||
sites_navigator();
|
sites_navigator();
|
||||||
|
Loading…
Reference in New Issue
Block a user