This commit is contained in:
2025-04-13 11:59:50 +02:00
parent 80640d2580
commit fe3191d4a2
21 changed files with 567 additions and 117 deletions

View File

@@ -73,7 +73,7 @@ class File(models.Model):
def mime_types(self):
mime = mimetypes.guess_type(self.pathname)
if mime:
return mime
return mime[0] or mime[1] or "application/octet-stream"
else:
return "application/octet-stream"
@@ -87,7 +87,21 @@ class File(models.Model):
@property
def accel_redirect(self):
return shlex.quote(f"{settings.NGINX_ACCEL_BASE}/{self.pathname}")
# Encode chaque partie du chemin séparément pour préserver la structure
encoded_parts = []
for part in self.pathname.parts:
# Ignorer un slash initial si présent
if part == '/' or part == '\\':
continue
encoded_parts.append(quote(part))
# Construction du chemin final avec le préfixe Nginx
if settings.NGINX_ACCEL_BASE.endswith('/'):
base = settings.NGINX_ACCEL_BASE.rstrip('/')
else:
base = settings.NGINX_ACCEL_BASE
return f"{base}/{'/'.join(encoded_parts)}"
@property
def disposition(self):