summaryrefslogtreecommitdiffstats
path: root/activities
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-12 07:22:11 -0700
committerAndrew Godwin2022-12-12 11:56:49 -0700
commit8ffe4bc1453660c1f211496074ebcc68c924327e (patch)
tree7503fdcd6aafd32e9ec75dc7190699e004cf2935 /activities
parent35a45f1c55fba69d690929c9420df565e7c5efcc (diff)
downloadtakahe-8ffe4bc1453660c1f211496074ebcc68c924327e.tar.gz
takahe-8ffe4bc1453660c1f211496074ebcc68c924327e.tar.bz2
takahe-8ffe4bc1453660c1f211496074ebcc68c924327e.zip
A better way of handling URIs between local/remote
Diffstat (limited to 'activities')
-rw-r--r--activities/models/post_attachment.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/activities/models/post_attachment.py b/activities/models/post_attachment.py
index 7b1ad6b..3b1f425 100644
--- a/activities/models/post_attachment.py
+++ b/activities/models/post_attachment.py
@@ -1,9 +1,9 @@
from functools import partial
-from django.conf import settings
from django.db import models
from core.uploads import upload_namer
+from core.uris import AutoAbsoluteUrl, RelativeAbsoluteUrl
from stator.models import State, StateField, StateGraph, StatorModel
@@ -72,19 +72,19 @@ class PostAttachment(StatorModel):
"image/webp",
]
- def thumbnail_url(self):
+ def thumbnail_url(self) -> RelativeAbsoluteUrl:
if self.thumbnail:
- return self.thumbnail.url
+ return RelativeAbsoluteUrl(self.thumbnail.url)
elif self.file:
- return self.file.url
+ return RelativeAbsoluteUrl(self.file.url)
else:
- return f"https://{settings.MAIN_DOMAIN}/proxy/post_attachment/{self.pk}/"
+ return AutoAbsoluteUrl(f"/proxy/post_attachment/{self.pk}/")
def full_url(self):
if self.file:
- return self.file.url
+ return RelativeAbsoluteUrl(self.file.url)
else:
- return f"https://{settings.MAIN_DOMAIN}/proxy/post_attachment/{self.pk}/"
+ return AutoAbsoluteUrl(f"/proxy/post_attachment/{self.pk}/")
### ActivityPub ###
@@ -105,8 +105,8 @@ class PostAttachment(StatorModel):
return {
"id": self.pk,
"type": "image" if self.is_image() else "unknown",
- "url": self.full_url(),
- "preview_url": self.thumbnail_url(),
+ "url": self.full_url().absolute,
+ "preview_url": self.thumbnail_url().absolute,
"remote_url": None,
"meta": {
"original": {