nexus-5/config/storage.py
2026-01-26 11:09:40 -05:00

28 lines
875 B
Python

"""
Custom S3 storage backend for Garage that returns nginx-proxied URLs.
Instead of returning direct S3 URLs like:
http://10.10.10.39:3900/nexus-media/uploads/...
Returns relative URLs that go through nginx:
/api/media/uploads/...
Nginx then handles auth and proxies to Garage's website mode.
"""
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class GarageS3Storage(S3Boto3Storage):
"""
S3Boto3Storage subclass that returns URLs through nginx proxy.
"""
def url(self, name, parameters=None, expire=None, http_method=None):
"""
Return a URL that goes through our nginx proxy instead of direct S3.
"""
# Return relative URL that nginx will proxy to S3
# MEDIA_URL is '/api/media/' so this becomes '/api/media/uploads/...'
return f"{settings.MEDIA_URL}{name}"