diff --git a/app.py b/app.py index 260bc93..7f30ec2 100644 --- a/app.py +++ b/app.py @@ -64,6 +64,24 @@ def list_dir(dir_path): current_dir=dir_path.rstrip('/'), content=content) + +@route('/img/') +def send_image(filename): + return static_file(filename, root=OBJECT_DIR) + +@route('/image/') +def image(file_path): + file_path = file_path.replace('/img/', '') + parts = file_path.split('/') + file_name = parts.pop() + return template('image', + current_dir=file_path.replace(file_name, ""), + name=file_name, + object={'type': 'image', + 'url': f"/img{file_path}" + } + ) + @route('/render/') def render(file_path): file_path = file_path.replace('/render/', '') diff --git a/utils/utils.py b/utils/utils.py index aec9d84..0218233 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -19,6 +19,7 @@ along with this program. If not, see . import os from pathlib import Path +import mimetypes BASE_DIR = os.path.abspath( os.path.join( @@ -29,18 +30,26 @@ OBJECT_DIR = os.path.join(BASE_DIR, 'objects') OBJECT_TYPES = ['gltf', 'glb', 'obj', 'fbx', 'stl', 'dae', 'json', 'ply'] def get_directory_content(dir_path): + mimetypes.init() content = [] for p in Path(dir_path).iterdir(): - file = Path(p) - if file.name.startswith("."): + file_path = Path(p) + file_name = Path(file_path.name) + if file_path.name.startswith("."): continue - model_type = (Path(file.name).suffix).lstrip('.').lower() - is_object_file = True if model_type in OBJECT_TYPES else False + file_extension = (Path(file_path.name).suffix).lstrip('.').lower() + is_object_file = True if file_extension in OBJECT_TYPES else False + is_dir = True if p.is_dir() else False + is_image = False + if not is_dir: + mimetype, _ = mimetypes.guess_type(str(Path(p))) + is_image = True if mimetype and 'image' in mimetype else False item = { 'name': os.path.basename(p), 'size': human_readable_bytes(os.path.getsize(p)), - 'is_dir': True if p.is_dir() else False, - 'is_object_file': is_object_file + 'is_dir': is_dir, + 'is_object_file': is_object_file, + 'is_image': is_image } content.append(item) return content diff --git a/views/_nav.tpl b/views/_nav.tpl new file mode 100644 index 0000000..1c6153f --- /dev/null +++ b/views/_nav.tpl @@ -0,0 +1,10 @@ +

+ + objects/{{current_dir}} +

+

+ + {{ object['type'] }}: + + {{name}} +

diff --git a/views/google.tpl b/views/google.tpl index cf3416d..eda361b 100644 --- a/views/google.tpl +++ b/views/google.tpl @@ -1,5 +1,7 @@ % rebase('base.tpl') +% include('_nav.tpl', current_dir=current_dir, object=object) + %end -

- - objects/{{current_dir}} -

-

- - {{ object['type'] }}: - - {{name}} -

-