details with mimetype
This commit is contained in:
@@ -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
|
||||
|
||||
26
code/app.py
26
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']):
|
||||
files.append(file)
|
||||
maxlen = max(maxlen, len(file))
|
||||
details = []
|
||||
details.append(
|
||||
"%%16s %%8s %%-%ds %%s"%( maxlen, )%(
|
||||
'Modified',
|
||||
'Size',
|
||||
'Name',
|
||||
'Type',
|
||||
)
|
||||
)
|
||||
details.append("="*80)
|
||||
for file in files:
|
||||
status = file_stat(share['path'],file)
|
||||
files.append(
|
||||
"%s %8s %s"%(
|
||||
details.append(
|
||||
"%%16s %%8s %%-%ds %%s"%( maxlen, )%(
|
||||
status['mtime'],
|
||||
status['size'],
|
||||
status['hsize'],
|
||||
status['name'],
|
||||
status['mime'],
|
||||
)
|
||||
)
|
||||
return "\n".join(files), 200
|
||||
|
||||
return "\n".join(details), 200
|
||||
|
||||
|
||||
@app.route('/file/size/<name>/<token>/<path:filename>', methods=['GET'])
|
||||
|
||||
@@ -2,3 +2,4 @@ flask
|
||||
gunicorn
|
||||
pycrypto
|
||||
requests
|
||||
python-magic
|
||||
|
||||
@@ -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"
|
||||
} || {
|
||||
|
||||
@@ -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,16 +59,20 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user