details with mimetype

This commit is contained in:
2018-08-21 11:03:23 +03:00
parent 9da02ed65b
commit e93668828c
5 changed files with 35 additions and 13 deletions

View File

@@ -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 = '&nbsp;' if HTML else ' '
for x in [space + 'B', 'KB', 'MB', 'GB', 'TB']:
if num < 1024.0: