details with mimetype
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user