diff --git a/code/Dockerfile b/code/Dockerfile index 9f4c126..bbf802d 100644 --- a/code/Dockerfile +++ b/code/Dockerfile @@ -3,7 +3,8 @@ RUN apk add --update \ python3 \ python3-dev \ py3-pip \ - build-base + build-base \ + libmagic COPY docker-requirements.txt /requirements.txt RUN pip3 install -r /requirements.txt COPY static /code/static diff --git a/code/app.py b/code/app.py index bf307ce..d6a72ba 100644 --- a/code/app.py +++ b/code/app.py @@ -14,7 +14,7 @@ from utils.utils import * from utils.crypt import * -__FLEES_VERSION__ = "20180820.0" +__FLEES_VERSION__ = "20180821.0" app = Flask(__name__) app.config.from_object(__name__) # Read config from json ! @@ -382,16 +382,32 @@ def file_ls(name, token): if not ok: return share files = [] + maxlen = 0 for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']): - status = file_stat(share['path'],file) - files.append( - "%s %8s %s"%( - status['mtime'], - status['size'], - status['name'], + files.append(file) + maxlen = max(maxlen, len(file)) + details = [] + details.append( + "%%16s %%8s %%-%ds %%s"%( maxlen, )%( + 'Modified', + 'Size', + 'Name', + 'Type', ) ) - return "\n".join(files), 200 + details.append("="*80) + for file in files: + status = file_stat(share['path'],file) + details.append( + "%%16s %%8s %%-%ds %%s"%( maxlen, )%( + status['mtime'], + status['hsize'], + status['name'], + status['mime'], + ) + ) + + return "\n".join(details), 200 @app.route('/file/size///', methods=['GET']) diff --git a/code/docker-requirements.txt b/code/docker-requirements.txt index 5a5def8..3f13af6 100644 --- a/code/docker-requirements.txt +++ b/code/docker-requirements.txt @@ -2,3 +2,4 @@ flask gunicorn pycrypto requests +python-magic diff --git a/code/templates/flip b/code/templates/flip index 8dec5fa..c7fe8db 100755 --- a/code/templates/flip +++ b/code/templates/flip @@ -48,7 +48,6 @@ _update_client() { } _list() { - printf "%-16s %8s %s\n" Date Size Name curl -s "$FLEES_ROOTURL/file/ls/$FLEES_SHARE/$FLEES_TOKEN" printf "\n" } @@ -63,7 +62,7 @@ _write() { _msg File to read needed, or use stdin exit 1 } - + _msg "Writing $NAME" [[ "$stream_in" -eq 1 ]] && { _write_stdin "$NAME" } || { diff --git a/code/utils/utils.py b/code/utils/utils.py index 3eb9dae..17a85ed 100644 --- a/code/utils/utils.py +++ b/code/utils/utils.py @@ -3,6 +3,7 @@ from datetime import datetime from flask import current_app as app import requests import re +import magic try: from urllib.request import pathname2url from urllib.request import urlparse @@ -58,20 +59,24 @@ def version_date(full_path): return None +def file_mime(filename): + return magic.from_file(filename, mime = True) def file_stat(path, filename): full_path = os.path.join(path, filename) s = os.stat(full_path) return { 'size': file_size_MB(s.st_size), + 'hsize': file_size_human(s.st_size, HTML = False), 'mtime': file_date_human(s.st_mtime), 'name': filename, 'url': path2url(filename), - 'editable': (s.st_size < 65536 and filename.endswith(".txt")) + 'editable': (s.st_size < 65536 and filename.endswith(".txt")), + 'mime': file_mime(full_path) } -def file_size_human(num,HTML=True): +def file_size_human(num, HTML = True): space = ' ' if HTML else ' ' for x in [space + 'B', 'KB', 'MB', 'GB', 'TB']: if num < 1024.0: