diff --git a/akarpov/files/previews/__init__.py b/akarpov/files/previews/__init__.py index 57cfe9a..51ab277 100644 --- a/akarpov/files/previews/__init__.py +++ b/akarpov/files/previews/__init__.py @@ -1,6 +1,9 @@ -from . import audio, image, video +from . import application, audio, image, text, video previews = { + "application": { + "zip": application.zip.view, + }, "audio": { "aac": audio.basic.view, "mpeg": audio.basic.view, @@ -14,12 +17,19 @@ "jpeg": image.basic.view, "png": image.basic.view, "avif": image.basic.view, + "bmp": image.basic.view, }, + "text": {"css": text.common.view, "plain": text.plain.view}, } +source_code = {} +for ext in text.common.language_previews.keys(): + source_code[ext] = text.common.view + extensions = { "mp4": video.mp4.view, "mp3": audio.basic.view, "avif": image.basic.view, + "bmp": image.basic.view, "mov": video.basic.view, -} +} | source_code diff --git a/akarpov/files/previews/application/__init__.py b/akarpov/files/previews/application/__init__.py new file mode 100644 index 0000000..6d0dc6b --- /dev/null +++ b/akarpov/files/previews/application/__init__.py @@ -0,0 +1 @@ +from . import zip # noqa diff --git a/akarpov/files/previews/application/zip.py b/akarpov/files/previews/application/zip.py new file mode 100644 index 0000000..95fcae1 --- /dev/null +++ b/akarpov/files/previews/application/zip.py @@ -0,0 +1,141 @@ +import zipfile +from collections import defaultdict + +from akarpov.files.models import File + +FILE_MARKER = "" + + +def attach(branch, trunk): + """ + Insert a branch of directories on its trunk. + """ + parts = branch.split("/", 1) + if len(parts) == 1: # branch is a file + trunk[FILE_MARKER].append(parts[0]) + else: + node, others = parts + if node not in trunk: + trunk[node] = defaultdict(dict, ((FILE_MARKER, []),)) + attach(others, trunk[node]) + + +def to_li(d, indent=0): + """ + Convert tree like structure to html ul li + """ + res = "" + for key, value in d.items(): + if key != FILE_MARKER: + if indent >= 2 or str(key).startswith("."): + in_res = ( + """ +
  • + """ + + str(key) + + "