Fix #1105: Can now launch server import from the UI

This commit is contained in:
Agate 2020-08-03 10:16:25 +02:00
parent 0a93aec8c9
commit 788c12748f
17 changed files with 476 additions and 6 deletions

View file

@ -1,3 +1,5 @@
import os
import pathlib
import mimetypes
import magic
@ -130,3 +132,21 @@ def increment_downloads_count(upload, user, wsgi_request):
duration = max(upload.duration or 0, settings.MIN_DELAY_BETWEEN_DOWNLOADS_COUNT)
cache.set(cache_key, 1, duration)
def browse_dir(root, path):
if ".." in path:
raise ValueError("Relative browsing is not allowed")
root = pathlib.Path(root)
real_path = root / path
dirs = []
files = []
for el in sorted(os.listdir(real_path)):
if os.path.isdir(real_path / el):
dirs.append({"name": el, "dir": True})
else:
files.append({"name": el, "dir": False})
return dirs + files