Compare commits

...

2 Commits

Author SHA1 Message Date
semantic-release-bot b0c0d9a83f chore(release): 8.1.1 [skip ci]
## [8.1.1](https://github.com/mediacms-io/mediacms/compare/v8.1.0...v8.1.1) (2026-05-18)

### Bug Fixes

* x-accell headers on uploaded poster ([#1526](https://github.com/mediacms-io/mediacms/issues/1526)) ([ae63a5a](https://github.com/mediacms-io/mediacms/commit/ae63a5af647c8865b96e6e50dda1ea9d29b5bd0b))
2026-05-18 11:25:57 +00:00
Markos Gogoulos ae63a5af64 fix: x-accell headers on uploaded poster (#1526) 2026-05-18 14:25:23 +03:00
5 changed files with 45 additions and 4 deletions
+6
View File
@@ -1,5 +1,11 @@
# Changelog # Changelog
## [8.1.1](https://github.com/mediacms-io/mediacms/compare/v8.1.0...v8.1.1) (2026-05-18)
### Bug Fixes
* x-accell headers on uploaded poster ([#1526](https://github.com/mediacms-io/mediacms/issues/1526)) ([ae63a5a](https://github.com/mediacms-io/mediacms/commit/ae63a5af647c8865b96e6e50dda1ea9d29b5bd0b))
## [8.1.0](https://github.com/mediacms-io/mediacms/compare/v8.0.8...v8.1.0) (2026-05-17) ## [8.1.0](https://github.com/mediacms-io/mediacms/compare/v8.0.8...v8.1.0) (2026-05-17)
### Features ### Features
+1 -1
View File
@@ -1 +1 @@
VERSION = "8.1.0" VERSION = "8.1.1"
+36 -1
View File
@@ -1,7 +1,9 @@
import re import re
from urllib.parse import unquote
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from django.db.models import Q
from django.http import HttpResponse from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_GET from django.views.decorators.http import require_GET
@@ -10,6 +12,7 @@ from ..methods import is_mediacms_editor
from ..models import Media from ..models import Media
UID_RE = re.compile(r"[0-9a-f]{32}") UID_RE = re.compile(r"[0-9a-f]{32}")
THUMBNAILS_PREFIX = "original/thumbnails/"
def _ttl(): def _ttl():
@@ -23,6 +26,32 @@ def _extract_uid(uri):
return match.group(0) if match else None return match.group(0) if match else None
def _relpath_from_uri(uri):
path = unquote(uri.split("?", 1)[0])
media_url = settings.MEDIA_URL
if path.startswith(media_url):
return path[len(media_url) :]
return None
def _lookup_uid_by_path(relpath):
path_key = f"xaccel:path:{relpath}"
cached = cache.get(path_key)
if cached is not None:
return cached or None
parts = relpath.split("/", 4)
if len(parts) < 5 or parts[2] != "user":
cache.set(path_key, "", _ttl())
return None
username = parts[3]
row = Media.objects.filter(user__username=username).filter(Q(uploaded_thumbnail=relpath) | Q(uploaded_poster=relpath)).values("uid").first()
uid_hex = row["uid"].hex if row else ""
cache.set(path_key, uid_hex, _ttl())
return uid_hex or None
def _lookup_state(uid): def _lookup_state(uid):
"""Return (state, owner_id) for a uid, or (None, None) if missing. """Return (state, owner_id) for a uid, or (None, None) if missing.
@@ -76,7 +105,13 @@ def media_auth(request):
uri = request.META.get("HTTP_X_ORIGINAL_URI", "") uri = request.META.get("HTTP_X_ORIGINAL_URI", "")
uid = _extract_uid(uri) uid = _extract_uid(uri)
if not uid: if not uid:
return HttpResponse(status=403) # User-uploaded thumbnails/posters don't have the uid in the filename.
# Fall back to a per-path lookup, scoped to /original/thumbnails/.
relpath = _relpath_from_uri(uri)
if relpath and relpath.startswith(THUMBNAILS_PREFIX):
uid = _lookup_uid_by_path(relpath)
if not uid:
return HttpResponse(status=403)
user = request.user user = request.user
cache_key = f"xaccel:auth:{uid}:{user.id if user.is_authenticated else 'anon'}" cache_key = f"xaccel:auth:{uid}:{user.id if user.is_authenticated else 'anon'}"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "mediacms", "name": "mediacms",
"version": "8.1.0", "version": "8.1.1",
"devDependencies": { "devDependencies": {
"@semantic-release/changelog": "^6.0.3", "@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1", "@semantic-release/git": "^10.0.1",
+1 -1
View File
@@ -2,4 +2,4 @@
exclude = .git,*migrations* exclude = .git,*migrations*
max-line-length = 119 max-line-length = 119
#ignore=F401,F403,E501,W503 #ignore=F401,F403,E501,W503
ignore=E501 ignore=E501,E203