Converted to python flask #1

Merged
itdominator merged 49 commits from develop into master 2021-10-03 19:49:44 +00:00
8 changed files with 97 additions and 84 deletions
Showing only changes of commit e6531f2ce1 - Show all commits

View File

@ -18,9 +18,15 @@ window_controllers = {}
def get_window_controller(): def get_window_controller():
if session.get('win_controller_id') is None: 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 session['win_controller_id'] = id
window_controllers.update( {id: WindowController() } ) window_controllers.update( {id: controller } )
return window_controllers[ session["win_controller_id"] ] return window_controllers[ session["win_controller_id"] ]
@ -28,7 +34,7 @@ def get_window_controller():
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def home(): def home():
if request.method == 'GET': 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() _dot_dots = view.get_dot_dots()
_current_directory = view.get_current_directory() _current_directory = view.get_current_directory()
return render_template('pages/index.html', current_directory = _current_directory, dot_dots = _dot_dots) 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']) @app.route('/api/list-files/<_hash>', methods=['GET', 'POST'])
def listFilesRoute(_hash): def listFilesRoute(_hash = None):
if request.method == 'POST': if request.method == 'POST':
view = get_window_controller().get_window(1).get_view(0) view = get_window_controller().get_window(1).get_view(0)
files = view.get_files_formatted()
_path = view.get_path() if _dot_dots[0][1] == HASH: # Refresh
_files = view.get_files_formatted() 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 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: else:
msg = "Can't manage the request type..." msg = "Can't manage the request type..."
return msgHandler.createMessageJSON("danger", msg) return msgHandler.createMessageJSON("danger", msg)
@ -96,7 +98,7 @@ def file_manager_action(_type, _hash = None):
if _type == "remux": if _type == "remux":
# NOTE: Need to actually implimint a websocket to communicate back to client that remux has completed. # 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. # 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) return view.remuxVideo(hash, fpath)
if _type == "run-locally": if _type == "run-locally":
view.openFilelocally(fpath) view.openFilelocally(fpath)

View File

View File

@ -23,9 +23,9 @@
{% block body_scripts_additional %} {% block body_scripts_additional %}
<script src="{{ url_for('static', filename='js/react-ui-logic.js')}}"></script>
<script src="{{ url_for('static', filename='js/ui-logic.js')}}"></script> <script src="{{ url_for('static', filename='js/ui-logic.js')}}"></script>
<script src="{{ url_for('static', filename='js/post-ajax.js')}}"></script> <script src="{{ url_for('static', filename='js/post-ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/ajax.js')}}"></script> <script src="{{ url_for('static', filename='js/ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/events.js')}}"></script> <script src="{{ url_for('static', filename='js/events.js')}}"></script>
<script src="{{ url_for('static', filename='js/react-ui-logic.js')}}"></script>
{% endblock body_scripts_additional %} {% endblock body_scripts_additional %}

View File

@ -14,26 +14,24 @@ class Launcher:
command = [] command = []
if lowerName.endswith(self.fvideos): if lowerName.endswith(self.fvideos):
player = self.fm_config["settings"]["media_app"] command = [self.media_app]
options = self.fm_config["settings"]["mplayer_options"].split()
command = [player]
if "mplayer" in player: if "mplayer" in self.media_app:
command += options command += self.mplayer_options
command += [file] command += [file]
elif lowerName.endswith(self.fimages): elif lowerName.endswith(self.fimages):
command = [self.fm_config["settings"]["image_app"], file] command = [self.image_app, file]
elif lowerName.endswith(self.fmusic): elif lowerName.endswith(self.fmusic):
command = [self.fm_config["settings"]["music_app"], file] command = [self.music_app], file]
elif lowerName.endswith(self.foffice): elif lowerName.endswith(self.foffice):
command = [self.fm_config["settings"]["office_app"], file] command = [self.office_app, file]
elif lowerName.endswith(self.ftext): elif lowerName.endswith(self.ftext):
command = [self.fm_config["settings"]["text_app"], file] command = [self.text_app, file]
elif lowerName.endswith(self.fpdf): elif lowerName.endswith(self.fpdf):
command = [self.fm_config["settings"]["pdf_app"], file] command = [self.pdf_app, file]
else: else:
command = [self.fm_config["settings"]["file_manager_app"], file] command = [self.file_manager_app, file]
self.logging.debug(command) self.logging.debug(command)
DEVNULL = open(os.devnull, 'w') DEVNULL = open(os.devnull, 'w')
@ -78,7 +76,7 @@ class Launcher:
def check_remux_space(self): def check_remux_space(self):
limit = self.fm_config["settings"]["remux_folder_max_disk_usage"] limit = self.remux_folder_max_disk_usage
try: try:
limit = int(limit) limit = int(limit)
except Exception as e: except Exception as e:

View File

@ -19,8 +19,14 @@ class Path:
def pop_from_path(self): def pop_from_path(self):
self.path.pop() 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() self.load_directory()
def set_path(self, path): def set_path(self, path):
self.path = list( filter(None, path.replace("\\", "/").split('/')) ) self.path = list( filter(None, path.replace("\\", "/").split('/')) )
self.load_directory() self.load_directory()
@ -30,3 +36,6 @@ class Path:
path = list( filter(None, home.replace("\\", "/").split('/')) ) path = list( filter(None, home.replace("\\", "/").split('/')) )
self.path = path self.path = path
self.load_directory() self.load_directory()
def get_home(self):
return os.path.expanduser("~") + self.subpath

View File

@ -10,12 +10,27 @@ from os import path
class Settings: class Settings:
ABS_THUMBS_PTH = None # Used for thumbnail generation 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 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 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') 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') foffice = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')

View File

@ -1,5 +1,5 @@
# Python imports # Python imports
import hashlib, json import hashlib
from os import listdir from os import listdir
from os.path import isdir, isfile, join from os.path import isdir, isfile, join
@ -13,27 +13,15 @@ from . import Path, Settings, Launcher
class View(Settings, Launcher, Path): class View(Settings, Launcher, Path):
def __init__(self): def __init__(self):
self.hideHiddenFiles = True
self.files = [] self.files = []
self.dirs = [] self.dirs = []
self.vids = [] self.vids = []
self.images = [] self.images = []
self.desktop = [] self.desktop = []
self.ungrouped = [] self.ungrouped = []
self.fm_config = self.getFileManagerSettings()
self.set_to_home() 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): def load_directory(self):
path = self.get_path() path = self.get_path()
self.dirs = [] self.dirs = []
@ -49,7 +37,7 @@ class View(Settings, Launcher, Path):
for f in listdir(path): for f in listdir(path):
file = join(path, f) file = join(path, f)
if self.hideHiddenFiles: if self.HIDE_HIDDEN_FILES:
if f.startswith('.'): if f.startswith('.'):
continue continue
@ -83,7 +71,7 @@ class View(Settings, Launcher, Path):
data.append([arr, self.hashText(arr)]) data.append([arr, self.hashText(arr)])
return data return data
def returnPathPartFromHash(self, hash): def get_path_part_from_hash(self, hash):
files = self.get_files() files = self.get_files()
for file in files: for file in files:
if hash == file[1]: 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): def get_current_directory(self):
return self.get_path() return self.get_path()

View File

@ -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"
}
}