diff --git a/backend/apps/files/tasks.py b/backend/apps/files/tasks.py index f1651f1..a3faa28 100644 --- a/backend/apps/files/tasks.py +++ b/backend/apps/files/tasks.py @@ -85,7 +85,7 @@ def generate_video_thumbnail( video_path = pstfile.file.path # Create output directory if it doesn't exist - output_dir = "/tmp/thumbgen/" + output_dir = os.path.join("/tmp/thumbgen/", str(file_id)) os.makedirs(output_dir, exist_ok=True) thumbnail_filename = f"thumbnail_{pstfile.hash_blake3}.png" @@ -114,6 +114,8 @@ def generate_video_thumbnail( 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: @@ -125,8 +127,6 @@ def generate_video_thumbnail( pstfile.save() - os.remove(thumbnail_file_path) - return f"Thumbnail generated and saved to {thumbnail_file_path}" except subprocess.CalledProcessError as e: