summaryrefslogtreecommitdiffstats
path: root/activities/models/post_attachment.py
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-16 23:00:10 -0700
committerAndrew Godwin2022-11-16 23:00:10 -0700
commit716d8a766ae0c4e2539f2df601269a3203bcd715 (patch)
tree6fca650c5960b06494ba322d4621727b81bd4fa0 /activities/models/post_attachment.py
parentb13c239213147b7acae4060aff35640d625b5169 (diff)
downloadtakahe-716d8a766ae0c4e2539f2df601269a3203bcd715.tar.gz
takahe-716d8a766ae0c4e2539f2df601269a3203bcd715.tar.bz2
takahe-716d8a766ae0c4e2539f2df601269a3203bcd715.zip
Show post images
Diffstat (limited to 'activities/models/post_attachment.py')
-rw-r--r--activities/models/post_attachment.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/activities/models/post_attachment.py b/activities/models/post_attachment.py
new file mode 100644
index 0000000..ee77d29
--- /dev/null
+++ b/activities/models/post_attachment.py
@@ -0,0 +1,55 @@
+from django.db import models
+
+from stator.models import State, StateField, StateGraph, StatorModel
+
+
+class PostAttachmentStates(StateGraph):
+ new = State(try_interval=30000)
+ fetched = State()
+
+ new.transitions_to(fetched)
+
+ @classmethod
+ async def handle_new(cls, instance):
+ # TODO: Fetch images to our own media storage
+ pass
+
+
+class PostAttachment(StatorModel):
+ """
+ An attachment to a Post. Could be an image, a video, etc.
+ """
+
+ post = models.ForeignKey(
+ "activities.post",
+ on_delete=models.CASCADE,
+ related_name="attachments",
+ )
+
+ state = StateField(graph=PostAttachmentStates)
+
+ mimetype = models.CharField(max_length=200)
+
+ # File may not be populated if it's remote and not cached on our side yet
+ file = models.FileField(upload_to="attachments/%Y/%m/%d/", null=True, blank=True)
+
+ remote_url = models.CharField(max_length=500, null=True, blank=True)
+
+ # This is the description for images, at least
+ name = models.TextField(null=True, blank=True)
+
+ width = models.IntegerField(null=True, blank=True)
+ height = models.IntegerField(null=True, blank=True)
+ focal_x = models.IntegerField(null=True, blank=True)
+ focal_y = models.IntegerField(null=True, blank=True)
+ blurhash = models.TextField(null=True, blank=True)
+
+ def is_image(self):
+ return self.mimetype in [
+ "image/apng",
+ "image/avif",
+ "image/gif",
+ "image/jpeg",
+ "image/png",
+ "image/webp",
+ ]