mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-06-07 09:24:20 -04:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a02d25d0b | |||
| c7a673bbbf | |||
| b0c0d9a83f | |||
| ae63a5af64 |
@@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## [8.1.2](https://github.com/mediacms-io/mediacms/compare/v8.1.1...v8.1.2) (2026-05-18)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove redundant check ([#1528](https://github.com/mediacms-io/mediacms/issues/1528)) ([c7a673b](https://github.com/mediacms-io/mediacms/commit/c7a673bbbf46efc37621dc4a5109a85fc10e1317))
|
||||
|
||||
## [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)
|
||||
|
||||
### Features
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
VERSION = "8.1.0"
|
||||
VERSION = "8.1.2"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import re
|
||||
from urllib.parse import unquote
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_GET
|
||||
@@ -10,6 +12,7 @@ from ..methods import is_mediacms_editor
|
||||
from ..models import Media
|
||||
|
||||
UID_RE = re.compile(r"[0-9a-f]{32}")
|
||||
THUMBNAILS_PREFIX = "original/thumbnails/"
|
||||
|
||||
|
||||
def _ttl():
|
||||
@@ -23,6 +26,32 @@ def _extract_uid(uri):
|
||||
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):
|
||||
"""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", "")
|
||||
uid = _extract_uid(uri)
|
||||
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
|
||||
cache_key = f"xaccel:auth:{uid}:{user.id if user.is_authenticated else 'anon'}"
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
from .keys import ensure_keys_exist
|
||||
|
||||
|
||||
class LtiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'lti'
|
||||
verbose_name = 'LTI 1.3 Integration'
|
||||
|
||||
def ready(self):
|
||||
"""Initialize LTI app - ensure keys exist"""
|
||||
try:
|
||||
ensure_keys_exist()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -21,10 +21,3 @@ def get_jwks():
|
||||
"""
|
||||
public_key = load_public_key()
|
||||
return {'keys': [public_key]}
|
||||
|
||||
|
||||
def ensure_keys_exist():
|
||||
"""Ensure key pair exists in database, generate if not"""
|
||||
from .models import LTIToolKeys
|
||||
|
||||
LTIToolKeys.get_or_create_keys()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mediacms",
|
||||
"version": "8.1.0",
|
||||
"version": "8.1.2",
|
||||
"devDependencies": {
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
|
||||
Reference in New Issue
Block a user