Merge remote-tracking branch 'origin/main'

This commit is contained in:
rimu 2024-11-19 18:54:45 +13:00
commit f9d8ac555a
3 changed files with 14 additions and 13 deletions

View file

@ -917,12 +917,9 @@ def post_json_to_model(activity_log, post_json, user, community) -> Post:
if post.url:
if is_image_url(post.url):
post.type = POST_TYPE_IMAGE
if 'image' in post_json and 'url' in post_json['image']:
image = File(source_url=post_json['image']['url'])
else:
image = File(source_url=post.url)
if alt_text:
image.alt_text = alt_text
image = File(source_url=post.url)
if alt_text:
image.alt_text = alt_text
db.session.add(image)
post.image = image
elif is_video_url(post.url):

View file

@ -267,7 +267,8 @@ class File(db.Model):
return self.source_url
elif self.file_path:
file_path = self.file_path[4:] if self.file_path.startswith('app/') else self.file_path
return f"https://{current_app.config['SERVER_NAME']}/{file_path}"
scheme = 'http' if current_app.config['SERVER_NAME'] == '127.0.0.1:5000' else 'https'
return f"{scheme}://{current_app.config['SERVER_NAME']}/{file_path}"
else:
return ''
@ -275,7 +276,8 @@ class File(db.Model):
if self.file_path is None:
return self.thumbnail_url()
file_path = self.file_path[4:] if self.file_path.startswith('app/') else self.file_path
return f"https://{current_app.config['SERVER_NAME']}/{file_path}"
scheme = 'http' if current_app.config['SERVER_NAME'] == '127.0.0.1:5000' else 'https'
return f"{scheme}://{current_app.config['SERVER_NAME']}/{file_path}"
def thumbnail_url(self):
if self.thumbnail_path is None:
@ -284,7 +286,8 @@ class File(db.Model):
else:
return ''
thumbnail_path = self.thumbnail_path[4:] if self.thumbnail_path.startswith('app/') else self.thumbnail_path
return f"https://{current_app.config['SERVER_NAME']}/{thumbnail_path}"
scheme = 'http' if current_app.config['SERVER_NAME'] == '127.0.0.1:5000' else 'https'
return f"{scheme}://{current_app.config['SERVER_NAME']}/{thumbnail_path}"
def delete_from_disk(self):
purge_from_cache = []
@ -1230,10 +1233,7 @@ class Post(db.Model):
if post.url:
if is_image_url(post.url):
post.type = constants.POST_TYPE_IMAGE
if 'image' in request_json['object'] and 'url' in request_json['object']['image']:
image = File(source_url=request_json['object']['image']['url'])
else:
image = File(source_url=post.url)
image = File(source_url=post.url)
if alt_text:
image.alt_text = alt_text
db.session.add(image)

View file

@ -332,6 +332,10 @@ def allowlist_html(html: str, a_target='_blank') -> str:
re_embedded_mp3 = re.compile(r'<img .*?src="(https://.*?\.mp3)".*?/>')
clean_html = re_embedded_mp3.sub(r'<audio controls><source src="\1" type="audio/mp3"></audio>', clean_html)
# replace the 'static' for images hotlinked to fandom sites with 'vignette'
re_fandom_hotlink = re.compile(r'<img alt="(.*?)" loading="lazy" src="https://static.wikia.nocookie.net')
clean_html = re_fandom_hotlink.sub(r'<img alt="\1" loading="lazy" src="https://vignette.wikia.nocookie.net', clean_html)
return clean_html