diff --git a/akarpov/files/previews/__init__.py b/akarpov/files/previews/__init__.py
index df2941f..e08a383 100644
--- a/akarpov/files/previews/__init__.py
+++ b/akarpov/files/previews/__init__.py
@@ -1,3 +1,20 @@
-from . import image, video
+from . import audio, image, video
-previews = {"video": {"mp4": video.mp4.view}, "image": {"jpeg": image.jpeg.view}}
+previews = {
+ "audio": {
+ "aac": audio.basic.view,
+ "mpeg": audio.basic.view,
+ "ogg": audio.basic.view,
+ "opus": audio.basic.view,
+ "wav": audio.basic.view,
+ "webm": audio.basic.view,
+ },
+ "video": {"mp4": video.mp4.view},
+ "image": {
+ "jpeg": image.basic.view,
+ "png": image.basic.view,
+ "avif": image.basic.view,
+ },
+}
+
+extensions = {"mp4": video.mp4.view, "mp3": audio.basic.view, "avif": image.basic.view}
diff --git a/akarpov/files/previews/audio/__init__.py b/akarpov/files/previews/audio/__init__.py
new file mode 100644
index 0000000..21123fd
--- /dev/null
+++ b/akarpov/files/previews/audio/__init__.py
@@ -0,0 +1 @@
+from . import basic # noqa
diff --git a/akarpov/files/previews/audio/basic.py b/akarpov/files/previews/audio/basic.py
new file mode 100644
index 0000000..4b26ac0
--- /dev/null
+++ b/akarpov/files/previews/audio/basic.py
@@ -0,0 +1,61 @@
+from akarpov.files.models import File
+
+
+def view(file: File) -> (str, str):
+ static = """
+ """
+ content = (
+ """
+
+
+
+
+
+
+
+
+
+
+
+ """
+ )
+
+ return static, content
diff --git a/akarpov/files/previews/audio/waves.py b/akarpov/files/previews/audio/waves.py
new file mode 100644
index 0000000..a079633
--- /dev/null
+++ b/akarpov/files/previews/audio/waves.py
@@ -0,0 +1,102 @@
+from akarpov.files.models import File
+
+
+def view(file: File) -> (str, str):
+ static = """
+
+ """
+ content = (
+ """
+
+ """
+ + """
+
+ """
+ )
+
+ return static, content
diff --git a/akarpov/files/previews/image/__init__.py b/akarpov/files/previews/image/__init__.py
index ae2d45a..21123fd 100644
--- a/akarpov/files/previews/image/__init__.py
+++ b/akarpov/files/previews/image/__init__.py
@@ -1 +1 @@
-from . import jpeg # noqa
+from . import basic # noqa
diff --git a/akarpov/files/previews/image/jpeg.py b/akarpov/files/previews/image/basic.py
similarity index 89%
rename from akarpov/files/previews/image/jpeg.py
rename to akarpov/files/previews/image/basic.py
index bb7aa50..c3302b0 100644
--- a/akarpov/files/previews/image/jpeg.py
+++ b/akarpov/files/previews/image/basic.py
@@ -10,6 +10,8 @@ def view(file: File) -> (str, str):
+
+
"""
+ """
@@ -23,10 +25,7 @@ def view(file: File) -> (str, str):
}
});
- // Get the Viewer.js instance after initialized
var viewer = $image.data('viewer');
-
- // View a list of images
$('#images').viewer();
"""
diff --git a/akarpov/files/previews/video/mp4.py b/akarpov/files/previews/video/mp4.py
index 93864ee..1ab30fa 100644
--- a/akarpov/files/previews/video/mp4.py
+++ b/akarpov/files/previews/video/mp4.py
@@ -9,7 +9,7 @@ def view(file: File) -> (str, str):
content = f"""
diff --git a/akarpov/files/views.py b/akarpov/files/views.py
index 973ea99..3f9b183 100644
--- a/akarpov/files/views.py
+++ b/akarpov/files/views.py
@@ -11,7 +11,7 @@
ChunkedUploadView,
)
from akarpov.files.models import File, Folder
-from akarpov.files.previews import previews
+from akarpov.files.previews import extensions, previews
class TopFolderView(LoginRequiredMixin, ListView):
@@ -41,10 +41,15 @@ def get_context_data(self, **kwargs):
static = ""
content = ""
if self.object.file_type:
- t1, t2 = self.object.file_type.split("/")
- if t1 in previews:
- if t2 in previews[t1]:
- static, content = previews[t1][t2](self.object)
+ if self.object.file_type == "application/octet-stream":
+ extension = self.object.file.path.split(".")[-1]
+ if extension in extensions:
+ static, content = extensions[extension](self.object)
+ else:
+ t1, t2 = self.object.file_type.split("/")
+ if t1 in previews:
+ if t2 in previews[t1]:
+ static, content = previews[t1][t2](self.object)
context["preview_static"] = static
context["preview_content"] = content
return context
diff --git a/akarpov/templates/files/view.html b/akarpov/templates/files/view.html
index 3d8b2a2..a8d2ff6 100644
--- a/akarpov/templates/files/view.html
+++ b/akarpov/templates/files/view.html
@@ -8,7 +8,7 @@
{% block content %}
-
+
-
+
{% autoescape off %}
{{ preview_content }}
{% endautoescape %}
diff --git a/compose/local/django/install_preview_dependencies b/compose/local/django/install_preview_dependencies
index 1f60066..5d74cba 100644
--- a/compose/local/django/install_preview_dependencies
+++ b/compose/local/django/install_preview_dependencies
@@ -7,4 +7,4 @@ dpkg -i draw.io-amd64-13.0.3.deb
rm draw.io-amd64-13.0.3.deb
apt-get purge -y --auto-remove -o APT:AutoRemove:RecommendsImportant=false && \
rm -rf /var/lib/apt/lists/*
-preview --check-dependencies``
+preview --check-dependencies