Skip to content
Snippets Groups Projects
Commit 73df8059 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

serve media files through app

parent 84a0b05e
No related branches found
No related tags found
No related merge requests found
Pipeline #11959 passed
# Generated by Django 4.1.4 on 2023-03-22 10:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contracts', '0008_alter_contracteesignaturerepresentative_options_and_more'),
]
operations = [
migrations.AlterField(
model_name='contractfile',
name='file',
field=models.FileField(upload_to='_private/', verbose_name='Soubor'),
),
]
...@@ -532,7 +532,7 @@ class ContractFile(NameStrMixin, models.Model): ...@@ -532,7 +532,7 @@ class ContractFile(NameStrMixin, models.Model):
file = models.FileField( file = models.FileField(
verbose_name="Soubor", verbose_name="Soubor",
upload_to="private/", upload_to="_private/",
) )
contract = models.ForeignKey( contract = models.ForeignKey(
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class MediaServerConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'media_server'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
app_name = "media_server"
urlpatterns = [
path(
"<path:path>",
views.view_media,
name="view_media",
),
]
import os
from django.core.files.storage import FileSystemStorage
from django_downloadview import StorageDownloadView
from django_http_exceptions import HTTPExceptions
# Create your views here.
storage = FileSystemStorage()
class MediaView(StorageDownloadView):
attachment = False
def get_path(self, *args, **kwargs) -> str:
path = super().get_path(*args, **kwargs)
# Make sure path is clean
path = os.path.normpath(path)
if path.startswith("_"): # Private path
raise HTTPExceptions.NOT_FOUND
return path
view_media = MediaView.as_view(storage=storage)
...@@ -20,13 +20,4 @@ server { ...@@ -20,13 +20,4 @@ server {
proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} }
location /media/ {
alias /var/opt/contract_registry/media/
}
location ~ /media/private/ {
deny all;
return 404;
}
} }
...@@ -64,6 +64,7 @@ INSTALLED_APPS = [ ...@@ -64,6 +64,7 @@ INSTALLED_APPS = [
"markdownx", "markdownx",
"pirates", "pirates",
"webpack_loader", "webpack_loader",
"media_server",
"shared", "shared",
"contracts", "contracts",
"oidc", "oidc",
......
...@@ -28,5 +28,6 @@ urlpatterns = [ ...@@ -28,5 +28,6 @@ urlpatterns = [
path("", include("users.urls")), path("", include("users.urls")),
path("markdownx/", include("markdownx.urls")), path("markdownx/", include("markdownx.urls")),
path("oidc/", include("oidc.urls")), path("oidc/", include("oidc.urls")),
path("media/", include("media_server.urls")),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
] + pirates_urlpatterns ] + pirates_urlpatterns
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment