This commit is contained in:
Eva
2025-06-06 05:51:58 +02:00
committed by GitHub

View File

@ -626,13 +626,12 @@ def update_post_content(post: model.Post, content: Optional[bytes]) -> None:
"Unhandled file type: %r" % post.mime_type "Unhandled file type: %r" % post.mime_type
) )
post.checksum = util.get_sha1(content) checksum = util.get_sha1(content)
post.checksum_md5 = util.get_md5(content)
other_post = ( other_post = (
db.session.query(model.Post) db.session.query(model.Post)
.filter(model.Post.checksum == post.checksum) .filter(model.Post.checksum == checksum)
.filter(model.Post.post_id != post.post_id) .filter(model.Post.post_id != post.post_id)
.one_or_none() .first()
) )
if ( if (
other_post other_post
@ -641,11 +640,6 @@ def update_post_content(post: model.Post, content: Optional[bytes]) -> None:
): ):
raise PostAlreadyUploadedError(other_post) raise PostAlreadyUploadedError(other_post)
if update_signature:
purge_post_signature(post)
post.signature = generate_post_signature(post, content)
post.file_size = len(content)
try: try:
image = images.Image(content) image = images.Image(content)
post.canvas_width = image.width post.canvas_width = image.width
@ -667,6 +661,15 @@ def update_post_content(post: model.Post, content: Optional[bytes]) -> None:
else: else:
post.canvas_width = None post.canvas_width = None
post.canvas_height = None post.canvas_height = None
post.checksum = checksum
post.checksum_md5 = util.get_md5(content)
post.file_size = len(content)
if update_signature:
purge_post_signature(post)
post.signature = generate_post_signature(post, content)
setattr(post, "__content", content) setattr(post, "__content", content)
@ -923,7 +926,7 @@ def search_by_image_exact(image_content: bytes) -> Optional[model.Post]:
return ( return (
db.session.query(model.Post) db.session.query(model.Post)
.filter(model.Post.checksum == checksum) .filter(model.Post.checksum == checksum)
.one_or_none() .first()
) )