diff --git a/src/core/routes/Routes.py b/src/core/routes/Routes.py index 6cdbee4..cfe28db 100644 --- a/src/core/routes/Routes.py +++ b/src/core/routes/Routes.py @@ -18,9 +18,15 @@ window_controllers = {} def get_window_controller(): if session.get('win_controller_id') is None: - id = secrets.token_hex(16) + id = secrets.token_hex(16) + controller = WindowController() + view = controller.get_window(1).get_view(0) + view.ABS_THUMBS_PTH = app.config['ABS_THUMBS_PTH'] + view.REMUX_FOLDER = app.config['REMUX_FOLDER'] + view.FFMPG_THUMBNLR = app.config['FFMPG_THUMBNLR'] + session['win_controller_id'] = id - window_controllers.update( {id: WindowController() } ) + window_controllers.update( {id: controller } ) return window_controllers[ session["win_controller_id"] ] @@ -28,7 +34,7 @@ def get_window_controller(): @app.route('/', methods=['GET', 'POST']) def home(): if request.method == 'GET': - view = get_window_controller().get_window(1).get_view(0) + view = get_window_controller().get_window(1).get_view(0) _dot_dots = view.get_dot_dots() _current_directory = view.get_current_directory() return render_template('pages/index.html', current_directory = _current_directory, dot_dots = _dot_dots) @@ -38,41 +44,37 @@ def home(): @app.route('/api/list-files/<_hash>', methods=['GET', 'POST']) -def listFilesRoute(_hash): +def listFilesRoute(_hash = None): if request.method == 'POST': - view = get_window_controller().get_window(1).get_view(0) - files = view.get_files_formatted() + view = get_window_controller().get_window(1).get_view(0) - _path = view.get_path() - _files = view.get_files_formatted() + if _dot_dots[0][1] == HASH: # Refresh + view.load_directory() + elif _dot_dots[1][1] == HASH: # Pop from dir + view.pop_from_path() + else: # Push to dir + _path = view.get_path_part_from_hash(HASH) + view.push_to_path(_path) + + + msg = "Log in with an Admin privlidged user to view the requested path!" + fave = db.session.query(Favorites).filter_by(link=_path).first() + _in_fave = "true" if fave else "false" + _dot_dots = view.get_dot_dots() + _files = view.get_files_formatted() + _path = view.get_current_directory() + is_locked = view.is_folder_locked(HASH) + + files.update({'in_fave': _in_fave}) + if is_locked and not oidc.user_loggedin: + return msgHandler.createMessageJSON("danger", msg) + elif is_locked and oidc.user_loggedin: + isAdmin = oidc.user_getfield("isAdmin") + if isAdmin != "yes" : + return msgHandler.createMessageJSON("danger", msg) - fave = db.session.query(Favorites).filter_by(link=path).first() - in_fave = "true" if fave else "false" - files.update({'in_fave': in_fave}) return files - # HASH = _hash.strip() - # pathPart = file_manager.returnPathPartFromHash(HASH) - # lockedFolders = config["settings"]["locked_folders"].split("::::") - # path = file_manager.getPath().split('/') - # lockedFolderInPath = False - # - # # Insure chilren folders are locked too. - # for folder in lockedFolders: - # if folder in path: - # lockedFolderInPath = True - # break - # - # isALockedFolder = (pathPart in lockedFolders or lockedFolderInPath) - # msg = "Log in with an Admin privlidged user to view the requested path!" - # if isALockedFolder and not oidc.user_loggedin: - # return msgHandler.createMessageJSON("danger", msg) - # elif isALockedFolder and oidc.user_loggedin: - # isAdmin = oidc.user_getfield("isAdmin") - # if isAdmin != "yes" : - # return msgHandler.createMessageJSON("danger", msg) - # - # return listFiles(HASH) else: msg = "Can't manage the request type..." return msgHandler.createMessageJSON("danger", msg) @@ -96,7 +98,7 @@ def file_manager_action(_type, _hash = None): if _type == "remux": # NOTE: Need to actually implimint a websocket to communicate back to client that remux has completed. # As is, the remux thread hangs until completion and client tries waiting until server reaches connection timeout. - # I.E....this is stupid but for now works + # I.E....this is stupid but for now works better than nothing return view.remuxVideo(hash, fpath) if _type == "run-locally": view.openFilelocally(fpath) diff --git a/src/core/static/js/react-ui-logic.js.js b/src/core/static/js/react-ui-logic.js.js new file mode 100644 index 0000000..e69de29 diff --git a/src/core/templates/pages/index.html b/src/core/templates/pages/index.html index 6b92c65..d0791a7 100644 --- a/src/core/templates/pages/index.html +++ b/src/core/templates/pages/index.html @@ -23,9 +23,9 @@ {% block body_scripts_additional %} + - {% endblock body_scripts_additional %} diff --git a/src/core/utils/shellfm/windows/Launcher.py b/src/core/utils/shellfm/windows/Launcher.py index 993a65f..0fdc3bb 100644 --- a/src/core/utils/shellfm/windows/Launcher.py +++ b/src/core/utils/shellfm/windows/Launcher.py @@ -14,26 +14,24 @@ class Launcher: command = [] if lowerName.endswith(self.fvideos): - player = self.fm_config["settings"]["media_app"] - options = self.fm_config["settings"]["mplayer_options"].split() - command = [player] + command = [self.media_app] - if "mplayer" in player: - command += options + if "mplayer" in self.media_app: + command += self.mplayer_options command += [file] elif lowerName.endswith(self.fimages): - command = [self.fm_config["settings"]["image_app"], file] + command = [self.image_app, file] elif lowerName.endswith(self.fmusic): - command = [self.fm_config["settings"]["music_app"], file] + command = [self.music_app], file] elif lowerName.endswith(self.foffice): - command = [self.fm_config["settings"]["office_app"], file] + command = [self.office_app, file] elif lowerName.endswith(self.ftext): - command = [self.fm_config["settings"]["text_app"], file] + command = [self.text_app, file] elif lowerName.endswith(self.fpdf): - command = [self.fm_config["settings"]["pdf_app"], file] + command = [self.pdf_app, file] else: - command = [self.fm_config["settings"]["file_manager_app"], file] + command = [self.file_manager_app, file] self.logging.debug(command) DEVNULL = open(os.devnull, 'w') @@ -78,7 +76,7 @@ class Launcher: def check_remux_space(self): - limit = self.fm_config["settings"]["remux_folder_max_disk_usage"] + limit = self.remux_folder_max_disk_usage try: limit = int(limit) except Exception as e: diff --git a/src/core/utils/shellfm/windows/Path.py b/src/core/utils/shellfm/windows/Path.py index d86ece9..8b38456 100644 --- a/src/core/utils/shellfm/windows/Path.py +++ b/src/core/utils/shellfm/windows/Path.py @@ -19,8 +19,14 @@ class Path: def pop_from_path(self): self.path.pop() + + if not self.go_past_home: + if self.get_home() not in self.get_path(): + self.set_to_home() + self.load_directory() + def set_path(self, path): self.path = list( filter(None, path.replace("\\", "/").split('/')) ) self.load_directory() @@ -30,3 +36,6 @@ class Path: path = list( filter(None, home.replace("\\", "/").split('/')) ) self.path = path self.load_directory() + + def get_home(self): + return os.path.expanduser("~") + self.subpath diff --git a/src/core/utils/shellfm/windows/Settings.py b/src/core/utils/shellfm/windows/Settings.py index 2fe71a3..3d3b173 100644 --- a/src/core/utils/shellfm/windows/Settings.py +++ b/src/core/utils/shellfm/windows/Settings.py @@ -10,12 +10,27 @@ from os import path class Settings: - ABS_THUMBS_PTH = None # Used for thumbnail generation and is set by passing in - REMUX_FOLDER = None # Used for Remuxed files and is set by passing in - FFMPG_THUMBNLR = None # Used for thumbnail generator binary and is set by passing in + ABS_THUMBS_PTH = None # Used for thumbnail generation and is set by passing in + REMUX_FOLDER = None # Used for Remuxed files and is set by passing in + FFMPG_THUMBNLR = None # Used for thumbnail generator binary and is set by passing in + HIDE_HIDDEN_FILES = True + + CONFIG_FILE = path.dirname(__file__) + '/webfm_config.json' + subpath = "/LazyShare" # modify 'home' folder path + + locked_folders = "Synced Backup::::venv::::flasks".split("::::") + mplayer_options = "-quiet -really-quiet -xy 1600 -geometry 50%:50%".split() + music_app = "/opt/deadbeef/bin/deadbeef" + media_app = "mpv" + image_app = "mirage" + office_app = "libreoffice" + pdf_app = "evince" + text_app = "leafpad" + file_manager_app = "spacefm" + lock_folder = True + go_past_home = False + remux_folder_max_disk_usage = "8589934592" - CONFIG_FILE = path.dirname(__file__) + '/webfm_config.json' - subpath = "/LazyShare" # modify 'home' folder path fvideos = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm') foffice = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf') diff --git a/src/core/utils/shellfm/windows/View.py b/src/core/utils/shellfm/windows/View.py index 7e97b69..8bbb185 100644 --- a/src/core/utils/shellfm/windows/View.py +++ b/src/core/utils/shellfm/windows/View.py @@ -1,5 +1,5 @@ # Python imports -import hashlib, json +import hashlib from os import listdir from os.path import isdir, isfile, join @@ -13,27 +13,15 @@ from . import Path, Settings, Launcher class View(Settings, Launcher, Path): def __init__(self): - self.hideHiddenFiles = True self.files = [] self.dirs = [] self.vids = [] self.images = [] self.desktop = [] self.ungrouped = [] - self.fm_config = self.getFileManagerSettings() + self.set_to_home() - - # Settings data - def getFileManagerSettings(self): - returnData = [] - with open(self.CONFIG_FILE) as infile: - try: - return json.load(infile) - except Exception as e: - print(repr(e)) - return ['', 'mplayer', 'xdg-open'] - def load_directory(self): path = self.get_path() self.dirs = [] @@ -49,7 +37,7 @@ class View(Settings, Launcher, Path): for f in listdir(path): file = join(path, f) - if self.hideHiddenFiles: + if self.HIDE_HIDDEN_FILES: if f.startswith('.'): continue @@ -83,7 +71,7 @@ class View(Settings, Launcher, Path): data.append([arr, self.hashText(arr)]) return data - def returnPathPartFromHash(self, hash): + def get_path_part_from_hash(self, hash): files = self.get_files() for file in files: if hash == file[1]: @@ -110,6 +98,23 @@ class View(Settings, Launcher, Path): } } + def is_folder_locked(self, hash): + if self.lock_folder: + path_parts = self.get_path().split('/') + file = self.get_path_part_from_hash(hash) + + # Insure chilren folders are locked too. + lockedFolderInPath = False + for folder in self.locked_folders: + if folder in path_parts: + lockedFolderInPath = True + break + + return (file in self.locked_folders or lockedFolderInPath) + else: + return False + + def get_current_directory(self): return self.get_path() diff --git a/src/core/utils/shellfm/windows/webfm_config.json b/src/core/utils/shellfm/windows/webfm_config.json deleted file mode 100644 index 0c3f8d6..0000000 --- a/src/core/utils/shellfm/windows/webfm_config.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "settings" : { - "media_app": "mpv", - "mplayer_options": "-quiet -really-quiet -xy 1600 -geometry 50%:50%", - "music_app": "/opt/deadbeef/bin/deadbeef", - "image_app": "mirage", - "office_app": "libreoffice", - "pdf_app": "evince", - "text_app": "leafpad", - "file_manager_app": "spacefm", - "do_refresh": "no", - "remux_folder_max_disk_usage": "8589934592", - "locked_folders": "Synced Backup::::venv::::flasks", - "folders_locked": "true" - } -}