From 3595af7bd239f3843aff3ae06df8932cff23173d Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 10 Dec 2022 12:16:08 -0700 Subject: Media proxy, caching and tuning docs Fixes #67 --- takahe/settings.py | 13 ++++++++++++- takahe/urls.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'takahe') diff --git a/takahe/settings.py b/takahe/settings.py index f508952..64a523a 100644 --- a/takahe/settings.py +++ b/takahe/settings.py @@ -118,6 +118,12 @@ class Settings(BaseSettings): #: Default cache backend CACHES_DEFAULT: CacheBackendUrl | None = None + #: User icon (avatar) caching backend + CACHES_AVATARS: CacheBackendUrl | None = None + + #: Media caching backend + CACHES_MEDIA: CacheBackendUrl | None = None + PGHOST: str | None = None PGPORT: int | None = 5432 PGNAME: str = "takahe" @@ -167,6 +173,7 @@ INSTALLED_APPS = [ "activities", "users", "stator", + "mediaproxy", ] MIDDLEWARE = [ @@ -351,7 +358,11 @@ if SETUP.MEDIA_BACKEND: else: raise ValueError(f"Unsupported media backend {parsed.scheme}") -CACHES = {"default": django_cache_url.parse(SETUP.CACHES_DEFAULT or "dummy://")} +CACHES = { + "default": django_cache_url.parse(SETUP.CACHES_DEFAULT or "dummy://"), + "avatars": django_cache_url.parse(SETUP.CACHES_AVATARS or "dummy://"), + "media": django_cache_url.parse(SETUP.CACHES_MEDIA or "dummy://"), +} if SETUP.ERROR_EMAILS: ADMINS = [("Admin", e) for e in SETUP.ERROR_EMAILS] diff --git a/takahe/urls.py b/takahe/urls.py index 66f176d..98d1cd5 100644 --- a/takahe/urls.py +++ b/takahe/urls.py @@ -5,6 +5,7 @@ from django.views.static import serve from activities.views import compose, explore, follows, posts, search, timelines from core import views as core +from mediaproxy import views as mediaproxy from stator import views as stator from users.views import activitypub, admin, auth, identity, settings @@ -176,6 +177,22 @@ urlpatterns = [ core.FlatPage.as_view(title="Server Rules", config_option="policy_rules"), name="rules", ), + # Media/image proxy + path( + "proxy/identity_icon//", + mediaproxy.IdentityIconCacheView.as_view(), + name="proxy_identity_icon", + ), + path( + "proxy/identity_image//", + mediaproxy.IdentityImageCacheView.as_view(), + name="proxy_identity_image", + ), + path( + "proxy/post_attachment//", + mediaproxy.PostAttachmentCacheView.as_view(), + name="proxy_post_attachment", + ), # Well-known endpoints and system actor path(".well-known/webfinger", activitypub.Webfinger.as_view()), path(".well-known/host-meta", activitypub.HostMeta.as_view()), -- cgit v1.2.3