diff --git a/akarpov/files/previews/__init__.py b/akarpov/files/previews/__init__.py index 14dadff..57b1184 100644 --- a/akarpov/files/previews/__init__.py +++ b/akarpov/files/previews/__init__.py @@ -3,26 +3,40 @@ previews = { "application": { "zip": application.zip.view, + "java-archive": application.zip.view, "doc": application.doc.view, "docx": application.docx.view, + "vnd.oasis.opendocument.text": application.odt.view, }, "audio": { "aac": audio.basic.view, "mpeg": audio.basic.view, - "ogg": audio.basic.view, + "ogg": audio.oga.view, "opus": audio.basic.view, "wav": audio.basic.view, "webm": audio.basic.view, }, - "video": {"mp4": video.mp4.view, "quicktime": video.basic.view}, + "video": { + "mp4": video.mp4.view, + "ogg": video.basic.view, + "mpeg": video.basic.view, + "quicktime": video.basic.view, + }, "image": { "jpeg": image.basic.view, "png": image.basic.view, "avif": image.basic.view, "bmp": image.basic.view, + "vnd.microsoft.icon": image.basic.view, "gif": image.gif.view, }, - "text": {"css": text.common.view, "plain": text.plain.view, "csv": text.csv.view}, + "text": { + "css": text.common.view, + "html": text.common.view, + "javascript": text.common.view, + "plain": text.plain.view, + "csv": text.csv.view, + }, } source_code = {} @@ -32,10 +46,20 @@ extensions = { "mp4": video.mp4.view, "mp3": audio.basic.view, + "opus": audio.basic.view, "avif": image.basic.view, "bmp": image.basic.view, + "jpeg": image.basic.view, + "jpg": image.basic.view, + "ico": image.basic.view, "mov": video.basic.view, + "ogv": video.basic.view, "doc": application.doc.view, "docx": application.docx.view, + "odt": application.odt.view, "gif": image.gif.view, + "zip": application.zip.view, + "jar": application.zip.view, + "mpeg": video.mp4.view, + "oga": audio.oga.view, } | source_code diff --git a/akarpov/files/previews/application/__init__.py b/akarpov/files/previews/application/__init__.py index 3a9b9a5..ce5d9df 100644 --- a/akarpov/files/previews/application/__init__.py +++ b/akarpov/files/previews/application/__init__.py @@ -1 +1 @@ -from . import doc, docx, zip # noqa +from . import doc, docx, odt, zip # noqa diff --git a/akarpov/files/previews/application/odt.py b/akarpov/files/previews/application/odt.py new file mode 100644 index 0000000..92932a7 --- /dev/null +++ b/akarpov/files/previews/application/odt.py @@ -0,0 +1,16 @@ +import textract + +from akarpov.files.models import File + + +def view(file: File): + static = "" + content = "" + text = ( + textract.process(file.file.path, extension="odt", output_encoding="utf8") + .decode("utf8") + .replace("\t", " ") + ) + for line in text.split("\n"): + content += f"
{line}
" + return static, content diff --git a/akarpov/files/previews/audio/__init__.py b/akarpov/files/previews/audio/__init__.py index 21123fd..29ac151 100644 --- a/akarpov/files/previews/audio/__init__.py +++ b/akarpov/files/previews/audio/__init__.py @@ -1 +1 @@ -from . import basic # noqa +from . import basic, oga # noqa diff --git a/akarpov/files/previews/audio/oga.py b/akarpov/files/previews/audio/oga.py new file mode 100644 index 0000000..36ce087 --- /dev/null +++ b/akarpov/files/previews/audio/oga.py @@ -0,0 +1,73 @@ +import textract + +from akarpov.files.models import File + + +def view(file: File) -> (str, str): + static = f""" + + """ + text = ( + textract.process(file.file.path, extension="ogg", output_encoding="utf8") + .decode("utf8") + .replace("\t", " ") + ) + content = ( + """ +