init
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user