From 7fd888aae29826c6cfa49a7073865d277fbf3bcf Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Tue, 25 Feb 2025 10:45:58 +0100 Subject: [PATCH] Fix: check if file is imported before saving to db --- backend/apps/files/tasks.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/apps/files/tasks.py b/backend/apps/files/tasks.py index 5228237..a3faa28 100644 --- a/backend/apps/files/tasks.py +++ b/backend/apps/files/tasks.py @@ -112,15 +112,17 @@ def generate_video_thumbnail( subprocess.run(cmd, check=True) + thumbnail_hash_blake3 = compute_file_hash_blake3(thumbnail_file_path) + + if pstfile.thumbnail_hash_blake3 == thumbnail_hash_blake3: + return "Thumbnail already exists for this video file." + # Update the PostFileModel's thumbnail field with the new file with open(thumbnail_file_path, "rb") as file: pstfile.thumbnail.save(thumbnail_filename, file) - pstfile.thumbnail_hash_blake3 = compute_file_hash_blake3( - thumbnail_file_path - ) + pstfile.thumbnail_hash_blake3 = thumbnail_hash_blake3 - print(compute_blur_hash(thumbnail_file_path)) pstfile.thumbnail_blur_hash = compute_blur_hash(thumbnail_file_path) pstfile.save()