save local copy of link posts where the link is to an image

This commit is contained in:
rimu 2024-03-04 10:56:17 +13:00
parent 4afcf56a7b
commit b9a88a7fa6

View file

@ -1222,6 +1222,9 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
post.url = request_json['object']['attachment'][0]['href'] post.url = request_json['object']['attachment'][0]['href']
if is_image_url(post.url): if is_image_url(post.url):
post.type = POST_TYPE_IMAGE post.type = POST_TYPE_IMAGE
image = File(source_url=request_json['object']['image']['url'])
db.session.add(image)
post.image = image
else: else:
post.type = POST_TYPE_LINK post.type = POST_TYPE_LINK
domain = domain_from_url(post.url) domain = domain_from_url(post.url)
@ -1247,7 +1250,7 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
if not domain.banned: if not domain.banned:
domain.post_count += 1 domain.post_count += 1
post.domain = domain post.domain = domain
if 'image' in request_json['object']: if 'image' in request_json['object'] and post.image is None:
image = File(source_url=request_json['object']['image']['url']) image = File(source_url=request_json['object']['image']['url'])
db.session.add(image) db.session.add(image)
post.image = image post.image = image