From 0ba445895ce9968fc7cedd0fc12e960e3397e8d9 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Thu, 12 Mar 2026 14:21:56 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20merge=20room=20na?= =?UTF-8?q?me=20regex=20and=20centralize=20patterns=20in=20enums?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Combine the regex used in Drive with the one from the recording feature and centralize them in the enums module. Although the module name suggests only enums, it also hosts shared constants used across the codebase. --- src/backend/core/api/viewsets.py | 12 +----------- src/backend/core/enums.py | 6 ++++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index 90d177b2..36705659 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -1,7 +1,6 @@ """API endpoints""" # pylint: disable=too-many-lines -import re import uuid from logging import getLogger from urllib.parse import unquote, urlparse @@ -34,6 +33,7 @@ from rest_framework import ( from core import enums, models, utils from core.api.filters import ListFileFilter +from core.enums import MEDIA_STORAGE_URL_PATTERN from core.recording.enums import FileExtension from core.recording.event.authentication import StorageEventAuthentication from core.recording.event.exceptions import ( @@ -78,16 +78,6 @@ from .feature_flag import FeatureFlag logger = getLogger(__name__) -FILE_FOLDER = settings.FILE_UPLOAD_PATH -UUID_REGEX = ( - r"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" -) -FILE_EXT_REGEX = r"[\d\w]+" -MEDIA_STORAGE_URL_PATTERN = re.compile( - f"{settings.MEDIA_URL:s}" - rf"(?P{FILE_FOLDER:s}/(?P{UUID_REGEX:s})\.{FILE_EXT_REGEX:s})$" -) - class NestedGenericViewSet(viewsets.GenericViewSet): """ diff --git a/src/backend/core/enums.py b/src/backend/core/enums.py index 2e3fa593..9f7e237a 100644 --- a/src/backend/core/enums.py +++ b/src/backend/core/enums.py @@ -17,6 +17,12 @@ RECORDING_STORAGE_URL_PATTERN = re.compile( f"/media/{settings.RECORDING_OUTPUT_FOLDER}/(?P{UUID_REGEX:s}).(?P{FILE_EXT_REGEX:s})" ) +MEDIA_STORAGE_URL_PATTERN = re.compile( + f"{settings.MEDIA_URL:s}" + rf"(?P{settings.FILE_UPLOAD_PATH:s}/(?P{UUID_REGEX:s})\.{FILE_EXT_REGEX:s})$" +) + + # Django sets `LANGUAGES` by default with all supported languages. We can use it for # the choice of languages which should not be limited to the few languages active in # the app.