uploads: Add LOCAL_AVATARS_DIR / LOCAL_FILES_DIR computed settings.

This avoids strewing "avatars" and "files" constants throughout.
This commit is contained in:
Alex Vandiver
2022-12-12 21:02:25 +00:00
committed by Alex Vandiver
parent 24f95a3788
commit 7ad06473b6
12 changed files with 60 additions and 42 deletions

View File

@@ -40,6 +40,7 @@ from .configured_settings import (
EXTRA_INSTALLED_APPS,
GOOGLE_OAUTH2_CLIENT_ID,
IS_DEV_DROPLET,
LOCAL_UPLOADS_DIR,
MEMCACHED_LOCATION,
MEMCACHED_USERNAME,
RATE_LIMITING_RULES,
@@ -539,6 +540,9 @@ if PRODUCTION or IS_DEV_DROPLET or os.getenv("EXTERNAL_HOST") is not None:
else:
STATIC_URL = "http://localhost:9991/static/"
LOCAL_AVATARS_DIR = os.path.join(LOCAL_UPLOADS_DIR, "avatars") if LOCAL_UPLOADS_DIR else None
LOCAL_FILES_DIR = os.path.join(LOCAL_UPLOADS_DIR, "files") if LOCAL_UPLOADS_DIR else None
# ZulipStorage is a modified version of ManifestStaticFilesStorage,
# and, like that class, it inserts a file hash into filenames
# to prevent the browser from using stale files from cache.

View File

@@ -141,6 +141,8 @@ S3_REGION: Optional[str] = None
S3_ENDPOINT_URL: Optional[str] = None
S3_SKIP_PROXY = True
LOCAL_UPLOADS_DIR: Optional[str] = None
LOCAL_AVATARS_DIR: Optional[str] = None
LOCAL_FILES_DIR: Optional[str] = None
MAX_FILE_UPLOAD_SIZE = 25
# Jitsi Meet video call integration; set to None to disable integration.

View File

@@ -125,10 +125,10 @@ i18n_urls = [
urls += i18n_urls
# On a production instance, these files would be served by nginx.
if settings.LOCAL_UPLOADS_DIR is not None:
if settings.LOCAL_AVATARS_DIR is not None:
avatars_url = path(
"user_avatars/<path:path>",
serve,
{"document_root": os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars")},
{"document_root": os.path.join(settings.LOCAL_AVATARS_DIR)},
)
urls += [avatars_url]