impliminting actual listing structure

pull/1/head
maximstewart 3 years ago
parent f6f7cfda58
commit 6c8317e598

@ -29,44 +29,79 @@ def get_window_controller():
def home():
if request.method == 'GET':
view = get_window_controller().get_window(1).get_view(0)
_path = view.get_path()
_files = view.get_files_formatted()
return render_template('pages/index.html', path=_path, files=_files)
_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)
return render_template('error.html',
title='Error!',
message='Must use GET request type...')
return render_template('error.html', title = 'Error!',
message = 'Must use GET request type...')
@app.route('/api/list-files/<_hash>', methods=['GET', 'POST'])
def listFilesRoute(_hash):
if request.method == 'POST':
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)
view = get_window_controller().get_window(1).get_view(0)
files = view.get_files_formatted()
_path = view.get_path()
_files = view.get_files_formatted()
return listFiles(HASH)
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)
@app.route('/api/file-manager-action/<_type>/<_hash>')
def file_manager_action(_type, _hash = None):
view = get_window_controller().get_window(1).get_view(0)
if _type == "reset-path" and _hash == None:
view.set_to_home()
return redirect("/")
folder = view.get_path()
file = view.returnPathPartFromHash(hash)
fpath = os.path.join(folder, file)
logging.debug(fpath)
if _type == "files":
return send_from_directory(folder, file)
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
return view.remuxVideo(hash, fpath)
if _type == "run-locally":
view.openFilelocally(fpath)
return msgHandler.createMessageJSON("success", msg)
@app.route('/api/get-favorites', methods=['GET', 'POST'])
def getAllFavoritesRoute():
@ -120,67 +155,3 @@ def manageFavoritesRoute(_action):
else:
msg = "Can't manage the request type..."
return msgHandler.createMessageJSON("danger", msg)
@app.route('/api/reset-path', methods=['GET', 'POST'])
def resetPath():
if request.method == 'GET':
view = get_window_controller().get_window(1).get_view(0)
view.set_to_home()
return redirect("/")
# Used to get files from non gunicorn root path...
# Allows us to pull images and stuff to user without simlinking.
@app.route('/api/files/<hash>')
def returnFile(hash):
view = get_window_controller().get_window(1).get_view(0)
folder = view.get_path()
file = view.returnPathPartFromHash(hash)
return send_from_directory(folder, file)
@app.route('/api/remux/<hash>')
def remuxRoute(hash):
view = get_window_controller().get_window(1).get_view(0)
folder = view.get_path()
file = view.returnPathPartFromHash(hash)
fpath = os.path.join(folder, file)
logging.debug(fpath)
return view.remuxVideo(hash, fpath)
@app.route('/api/run-locally/<hash>')
def runLocallyRoute(hash):
view = get_window_controller().get_window(1).get_view(0)
folder = view.get_path()
file = view.returnPathPartFromHash(hash)
fpath = os.path.join(folder, file)
logging.debug(fpath)
view.openFilelocally(fpath)
msg = "Opened media..."
return msgHandler.createMessageJSON("success", msg)
def listFiles(HASH):
state = file_manager.generateLists(HASH)
if "error" in state:
msg = "Listing files failed..."
return msgHandler.createMessageJSON("danger", msg)
path = file_manager.getPath()
fave = db.session.query(Favorites).filter_by(link=path).first()
in_fave = "true" if fave else "false"
dirs = json.dumps( file_manager.getDirs() )
vids = json.dumps( file_manager.getVids() )
imgs = json.dumps( file_manager.getImgs() )
files = json.dumps( file_manager.getFiles() )
return '{"path_head":"' + path + '"' + \
',"in_fave":"' + in_fave + '"' + \
',"list":{"dirs":' + dirs + \
', "vids":' + vids + \
', "imgs":' + imgs + \
', "files":' + files + '}}'

@ -1,3 +1,20 @@
// {% for file in files['files'] %}
// <div class="col-sm-12 col-md-6 col-lg-4">
// <div class="card">
// <div class="card-header">{{file[0]}}</div>
// <div class="card-body">
// <img class="image-style" src="/api/files/{{file[1]}}" alt="{{file[0]}}" />
// </div>
// <div class="card-footer">
// <input app="{{file[1]}}" class="btn btn-secondary btn-sm" type="button" value="Launch"/>
// <input app="{{file[1]}}" class="btn btn-secondary btn-sm" type="button" value="Launch Locally"/>
// </div>
// </div>
// </div>
// {% endfor %}
// Message handler
const displayMessage = (message, type, timeout, msgWindow = "page-alert-zone") => {
let alertField = document.getElementById(msgWindow);

@ -1,4 +1,4 @@
{% if files %}
{% if current_directory %}
<nav class="navbar navbar-expand-sm bg-dark navbar-dark justify-content-center text-center fixed-bottom">
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarTogglerFooter" aria-controls="navbarTogglerFooter"
@ -10,7 +10,7 @@
<div class="col col-lg-auto">
<ul class="navbar-nav">
<li class="nav-item">
<span id="currentDirectory">{{path}}</span>
<span id="currentDirectory">{{current_directory}}</span>
</li>
</ul>
</div>

@ -7,12 +7,12 @@
<div id="navbarTogglerHeader" class="row collapse navbar-collapse">
<div class="col-sm">
{% if files %}
{% if current_directory %}
<li class="nav-item">
<div class="input-group input-group-sm justify-content-center">
<button title="Other Options..." class="btn btn-secondary btn-sm" data-toggle="modal" data-target="#options-modal"></button>
<button title="Refresh..." id="refresh-btn" class="btn btn-sm btn-secondary" hash="{{files['files'][0][1]}}"></button>
<button title="Back..." id="back-btn" class="btn btn-sm btn-secondary" hash="{{files['files'][1][1]}}"></button>
<button title="Refresh..." id="refresh-btn" class="btn btn-sm btn-secondary" hash="{{dot_dots[0][1]}}"></button>
<button title="Back..." id="back-btn" class="btn btn-sm btn-secondary" hash="{{dot_dots[1][1]}}"></button>
<input id="search-files-field" type="text" class="form-control" aria-label="Search..." placeholder="Search..." style="max-width: 260px">
<div class="input-group-prepend">

@ -15,20 +15,6 @@
{% block body_content_additional %}
<div id="files" class="row">
{% for file in files['files'] %}
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="card">
<div class="card-header">{{file[0]}}</div>
<div class="card-body">
<img class="image-style" src="/api/files/{{file[1]}}" alt="{{file[0]}}" />
</div>
<div class="card-footer">
<input app="{{file[1]}}" class="btn btn-secondary btn-sm" type="button" value="Launch"/>
<input app="{{file[1]}}" class="btn btn-secondary btn-sm" type="button" value="Launch Locally"/>
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock body_content_additional %}

@ -1,5 +1,4 @@
# System import
import json
from os import path

@ -1,5 +1,5 @@
# Python imports
import hashlib
import hashlib, json
from os import listdir
from os.path import isdir, isfile, join
@ -15,7 +15,7 @@ class View(Settings, Launcher, Path):
def __init__(self):
self.hideHiddenFiles = True
self.files = []
self.dirs = ['.', '..']
self.dirs = []
self.vids = []
self.images = []
self.desktop = []
@ -36,7 +36,7 @@ class View(Settings, Launcher, Path):
def load_directory(self):
path = self.get_path()
self.dirs = ['.', '..']
self.dirs = []
self.vids = []
self.images = []
self.desktop = []
@ -91,15 +91,31 @@ class View(Settings, Launcher, Path):
return None
def get_files_formatted(self):
files = self.hashSet(self.files),
dirs = self.hashSet(self.dirs),
videos = self.hashSet(self.vids),
images = self.hashSet(self.images),
desktops = self.hashSet(self.desktop),
ungrouped = self.hashSet(self.ungrouped)
return {
'files': self.hashSet(self.files),
'dirs': self.hashSet(self.dirs),
'videos': self.hashSet(self.vids),
'images': self.hashSet(self.images),
'desktops': self.hashSet(self.desktop),
'ungrouped': self.hashSet(self.ungrouped)
'path_head': self.get_path(),
'list': {
'files': files,
'dirs': dirs,
'videos': videos,
'images': images,
'desktops': desktops,
'ungrouped': ungrouped
}
}
def get_current_directory(self):
return self.get_path()
def get_dot_dots(self):
return self.hashSet(['.', '..'])
def get_files(self):
return self.hashSet(self.files)

Loading…
Cancel
Save