parseDesignFile.ts is dead code — Gallery upload ships hash-derived fake metrics #72

Closed
opened 2026-09-14 03:17:02 +00:00 by Mark · 0 comments
Owner

Where:

  • Parser: src/components/gallery/parseDesignFile.ts (156 lines, exports parseDesignFile and extractExtension).
  • Caller: src/pages/Gallery.tsx:17, 153 imports designFromFile from src/components/gallery/data.ts:84.
  • Verified: grep -rn 'parseDesignFile' src/ returns only the export line — no imports anywhere.

Bug:

  • designFromFile (data.ts:84-109) writes stitchCount = 1000 + (hash % 49000), threadCount = (hash % 10) + 1, and 4 hash-derived thumbnailColors for every upload.
  • The real PES/DST/SVG/PDF parsers in parseDesignFile.ts (which read #PEC0001 magic, count non-terminating stitch triplets, parse SVG fill attributes) are never called.
  • Users uploading real .pes files see 1k–50k fake stitch counts and arbitrary color swatches in their Gallery cards.

Fix consistent with existing patterns:
Wire the parser into the upload handler. Change src/pages/Gallery.tsx:147-164 handleFileChange from sync to async:

const handleFileChange = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => {
  const files = e.target.files;
  if (!files || files.length === 0) return;
  const imported: Design[] = [];
  for (let i = 0; i < files.length; i++) {
    const file = files[i];
    const base = designFromFile(file);             // existing sync helper, gives id/folderId/hoop/editedAt
    const parsed = await parseDesignFile(file);    // new wire-up
    imported.push({ ...base, stitchCount: parsed.stitchCount, threadCount: parsed.threadCount, thumbnailColors: parsed.thumbnailColors });
  }
  setDesigns((prev) => [...imported, ...prev]);
  showToast(imported.length === 1 ? `Uploaded ${imported[0].filename} to Unsorted` : `Uploaded ${imported.length} designs to Unsorted`);
  e.target.value = '';
}, [showToast]);

Add parseDesignFile to the import list on Gallery.tsx:12-18.

Acceptance: an uploaded flower.pes shows the real PEC stitch count in the card (not 1000 + hash%49000).

**Where:** - Parser: `src/components/gallery/parseDesignFile.ts` (156 lines, exports `parseDesignFile` and `extractExtension`). - Caller: `src/pages/Gallery.tsx:17, 153` imports `designFromFile` from `src/components/gallery/data.ts:84`. - Verified: `grep -rn 'parseDesignFile' src/` returns only the export line — no imports anywhere. **Bug:** - `designFromFile` (`data.ts:84-109`) writes `stitchCount = 1000 + (hash % 49000)`, `threadCount = (hash % 10) + 1`, and 4 hash-derived `thumbnailColors` for every upload. - The real PES/DST/SVG/PDF parsers in `parseDesignFile.ts` (which read `#PEC0001` magic, count non-terminating stitch triplets, parse SVG fill attributes) are never called. - Users uploading real `.pes` files see 1k–50k fake stitch counts and arbitrary color swatches in their Gallery cards. **Fix consistent with existing patterns:** Wire the parser into the upload handler. Change `src/pages/Gallery.tsx:147-164` `handleFileChange` from sync to async: ```ts const handleFileChange = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => { const files = e.target.files; if (!files || files.length === 0) return; const imported: Design[] = []; for (let i = 0; i < files.length; i++) { const file = files[i]; const base = designFromFile(file); // existing sync helper, gives id/folderId/hoop/editedAt const parsed = await parseDesignFile(file); // new wire-up imported.push({ ...base, stitchCount: parsed.stitchCount, threadCount: parsed.threadCount, thumbnailColors: parsed.thumbnailColors }); } setDesigns((prev) => [...imported, ...prev]); showToast(imported.length === 1 ? `Uploaded ${imported[0].filename} to Unsorted` : `Uploaded ${imported.length} designs to Unsorted`); e.target.value = ''; }, [showToast]); ``` Add `parseDesignFile` to the import list on `Gallery.tsx:12-18`. Acceptance: an uploaded `flower.pes` shows the real PEC stitch count in the card (not `1000 + hash%49000`).
Mark changed title from parseDesignFile.ts is dead code — the Gallery upload path uses hash-derived fake metrics instead to parseDesignFile.ts is dead code — Gallery upload ships hash-derived fake metrics 2026-09-14 03:19:53 +00:00
Mark 2026-09-14 03:49:28 +00:00
Sign in to join this conversation.
No description provided.