details with mimetype
This commit is contained in:
@@ -3,7 +3,8 @@ RUN apk add --update \
|
|||||||
python3 \
|
python3 \
|
||||||
python3-dev \
|
python3-dev \
|
||||||
py3-pip \
|
py3-pip \
|
||||||
build-base
|
build-base \
|
||||||
|
libmagic
|
||||||
COPY docker-requirements.txt /requirements.txt
|
COPY docker-requirements.txt /requirements.txt
|
||||||
RUN pip3 install -r /requirements.txt
|
RUN pip3 install -r /requirements.txt
|
||||||
COPY static /code/static
|
COPY static /code/static
|
||||||
|
|||||||
26
code/app.py
26
code/app.py
@@ -14,7 +14,7 @@ from utils.utils import *
|
|||||||
from utils.crypt import *
|
from utils.crypt import *
|
||||||
|
|
||||||
|
|
||||||
__FLEES_VERSION__ = "20180820.0"
|
__FLEES_VERSION__ = "20180821.0"
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(__name__)
|
app.config.from_object(__name__)
|
||||||
# Read config from json !
|
# Read config from json !
|
||||||
@@ -382,16 +382,32 @@ def file_ls(name, token):
|
|||||||
if not ok:
|
if not ok:
|
||||||
return share
|
return share
|
||||||
files = []
|
files = []
|
||||||
|
maxlen = 0
|
||||||
for file in iter_folder_files(share['path'], version_folder = app.config['VERSION_FOLDER']):
|
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)
|
status = file_stat(share['path'],file)
|
||||||
files.append(
|
details.append(
|
||||||
"%s %8s %s"%(
|
"%%16s %%8s %%-%ds %%s"%( maxlen, )%(
|
||||||
status['mtime'],
|
status['mtime'],
|
||||||
status['size'],
|
status['hsize'],
|
||||||
status['name'],
|
status['name'],
|
||||||
|
status['mime'],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return "\n".join(files), 200
|
|
||||||
|
return "\n".join(details), 200
|
||||||
|
|
||||||
|
|
||||||
@app.route('/file/size/<name>/<token>/<path:filename>', methods=['GET'])
|
@app.route('/file/size/<name>/<token>/<path:filename>', methods=['GET'])
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ flask
|
|||||||
gunicorn
|
gunicorn
|
||||||
pycrypto
|
pycrypto
|
||||||
requests
|
requests
|
||||||
|
python-magic
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ _update_client() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_list() {
|
_list() {
|
||||||
printf "%-16s %8s %s\n" Date Size Name
|
|
||||||
curl -s "$FLEES_ROOTURL/file/ls/$FLEES_SHARE/$FLEES_TOKEN"
|
curl -s "$FLEES_ROOTURL/file/ls/$FLEES_SHARE/$FLEES_TOKEN"
|
||||||
printf "\n"
|
printf "\n"
|
||||||
}
|
}
|
||||||
@@ -63,7 +62,7 @@ _write() {
|
|||||||
_msg File to read needed, or use stdin
|
_msg File to read needed, or use stdin
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
_msg "Writing $NAME"
|
||||||
[[ "$stream_in" -eq 1 ]] && {
|
[[ "$stream_in" -eq 1 ]] && {
|
||||||
_write_stdin "$NAME"
|
_write_stdin "$NAME"
|
||||||
} || {
|
} || {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from datetime import datetime
|
|||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
|
import magic
|
||||||
try:
|
try:
|
||||||
from urllib.request import pathname2url
|
from urllib.request import pathname2url
|
||||||
from urllib.request import urlparse
|
from urllib.request import urlparse
|
||||||
@@ -58,20 +59,24 @@ def version_date(full_path):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def file_mime(filename):
|
||||||
|
return magic.from_file(filename, mime = True)
|
||||||
|
|
||||||
def file_stat(path, filename):
|
def file_stat(path, filename):
|
||||||
full_path = os.path.join(path, filename)
|
full_path = os.path.join(path, filename)
|
||||||
s = os.stat(full_path)
|
s = os.stat(full_path)
|
||||||
return {
|
return {
|
||||||
'size': file_size_MB(s.st_size),
|
'size': file_size_MB(s.st_size),
|
||||||
|
'hsize': file_size_human(s.st_size, HTML = False),
|
||||||
'mtime': file_date_human(s.st_mtime),
|
'mtime': file_date_human(s.st_mtime),
|
||||||
'name': filename,
|
'name': filename,
|
||||||
'url': path2url(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 ' '
|
space = ' ' if HTML else ' '
|
||||||
for x in [space + 'B', 'KB', 'MB', 'GB', 'TB']:
|
for x in [space + 'B', 'KB', 'MB', 'GB', 'TB']:
|
||||||
if num < 1024.0:
|
if num < 1024.0:
|
||||||
|
|||||||
Reference in New Issue
Block a user