Fix default storage setting and use new STORAGES

as DEFAULT_FILE_STORAGE and STORAGES are mutually exclusive
pull/573/head
Christof Dorner 2023-05-08 09:55:09 +02:00
rodzic dcc4a5723e
commit 87cda1e064
1 zmienionych plików z 9 dodań i 2 usunięć

Wyświetl plik

@ -404,14 +404,18 @@ if SETUP.MEDIA_BACKEND:
parsed = urllib.parse.urlparse(SETUP.MEDIA_BACKEND)
query = urllib.parse.parse_qs(parsed.query)
if parsed.scheme == "gs":
DEFAULT_FILE_STORAGE = "core.uploads.TakaheGoogleCloudStorage"
STORAGES["default"] = {
"BACKEND": "core.uploads.TakaheGoogleCloudStorage",
}
GS_BUCKET_NAME = parsed.path.lstrip("/")
GS_QUERYSTRING_AUTH = False
if parsed.hostname is not None:
port = parsed.port or 443
GS_CUSTOM_ENDPOINT = f"https://{parsed.hostname}:{port}"
elif parsed.scheme == "s3":
DEFAULT_FILE_STORAGE = "core.uploads.TakaheS3Storage"
STORAGES["default"] = {
"BACKEND": "core.uploads.TakaheS3Storage",
}
AWS_STORAGE_BUCKET_NAME = parsed.path.lstrip("/")
AWS_QUERYSTRING_AUTH = False
AWS_DEFAULT_ACL = SETUP.MEDIA_BACKEND_S3_ACL
@ -425,6 +429,9 @@ if SETUP.MEDIA_BACKEND:
media_url_parsed = urllib.parse.urlparse(SETUP.MEDIA_URL)
AWS_S3_CUSTOM_DOMAIN = media_url_parsed.hostname
elif parsed.scheme == "local":
STORAGES["default"] = {
"BACKEND": "django.core.files.storage.FileSystemStorage",
}
if not (MEDIA_ROOT and MEDIA_URL):
raise ValueError(
"You must provide MEDIA_ROOT and MEDIA_URL for a local media backend"