From 4c86e6bddf579f2d05c5cc070698e264cd04f6e2 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Tue, 13 Jan 2026 20:32:32 +1300 Subject: [PATCH] fix(21-01): unify image hashing to MD5 - Replace position-based sampling hash with MD5 in imageStorage.ts - Add computeContentHash helper function - Consistent with save-generation API (Phase 13 decision) Co-Authored-By: Claude Opus 4.5 --- src/utils/imageStorage.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils/imageStorage.ts b/src/utils/imageStorage.ts index 32797dd0..79875395 100644 --- a/src/utils/imageStorage.ts +++ b/src/utils/imageStorage.ts @@ -1,5 +1,14 @@ import { WorkflowNode, WorkflowNodeData } from "@/types"; import { WorkflowFile } from "@/store/workflowStore"; +import crypto from "crypto"; + +/** + * Compute MD5 hash of image content for deduplication + * Consistent with save-generation API (Phase 13 decision) + */ +function computeContentHash(data: string): string { + return crypto.createHash("md5").update(data).digest("hex"); +} /** * Generate a unique image ID for external storage @@ -203,12 +212,9 @@ async function saveImageAndGetId( savedImageIds: Map, folder: "inputs" | "generations" = "inputs" ): Promise { - // Create a hash using length + samples from different parts of the data - // This avoids issues where all images of the same format have identical headers + // Use MD5 hash for reliable deduplication (consistent with save-generation API, Phase 13 decision) // Include folder in hash so same image in different folders gets different IDs - const len = imageData.length; - const mid = Math.floor(len / 2); - const hash = `${folder}-${len}-${imageData.substring(50, 100)}-${imageData.substring(mid, mid + 50)}-${imageData.substring(Math.max(0, len - 50))}`; + const hash = `${folder}-${computeContentHash(imageData)}`; if (savedImageIds.has(hash)) { return savedImageIds.get(hash)!;