Merge pull request #1242 from bookwyrm-social/image-federation
Fixes image federation
This commit is contained in:
@ -13,6 +13,7 @@ from django.db import models
|
||||
from django.forms import ClearableFileInput, ImageField as DjangoImageField
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from bookwyrm import activitypub
|
||||
from bookwyrm.connectors import get_image
|
||||
from bookwyrm.sanitize_html import InputHtmlParser
|
||||
@ -354,7 +355,8 @@ def image_serializer(value, alt):
|
||||
url = value.url
|
||||
else:
|
||||
return None
|
||||
url = "https://%s%s" % (DOMAIN, url)
|
||||
if not url[:4] == "http":
|
||||
url = "https://{:s}{:s}".format(DOMAIN, url)
|
||||
return activitypub.Document(url=url, name=alt)
|
||||
|
||||
|
||||
|
@ -426,6 +426,15 @@ class ActivitypubFields(TestCase):
|
||||
self.assertIsInstance(loaded_image, list)
|
||||
self.assertIsInstance(loaded_image[1], ContentFile)
|
||||
|
||||
def test_image_serialize(self):
|
||||
"""make sure we're creating sensible image paths"""
|
||||
ValueMock = namedtuple("ValueMock", ("url"))
|
||||
value_mock = ValueMock("/images/fish.jpg")
|
||||
result = fields.image_serializer(value_mock, "hello")
|
||||
self.assertEqual(result.type, "Document")
|
||||
self.assertEqual(result.url, "https://your.domain.here/images/fish.jpg")
|
||||
self.assertEqual(result.name, "hello")
|
||||
|
||||
def test_datetime_field(self):
|
||||
"""this one is pretty simple, it just has to use isoformat"""
|
||||
instance = fields.DateTimeField()
|
||||
|
Reference in New Issue
Block a user