[object Object]

← back to Wallco Ai

TIF lookup: match both <id>.tif and <category>/design_<id>.tif

c9f7813086dd19fbc387600e7e5fc4787f09d335 · 2026-06-02 08:12:34 -0700 · Steve Abrams

build-tif.py writes data/tif/<id>.tif (flat) but older rows used
data/tif/<category>/design_<id>.tif — findTifOnDisk + the colorway source
resolver now try both basenames, flat and one level deep. Verified locally:
both conventions resolve to 200 image/jpeg.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit c9f7813086dd19fbc387600e7e5fc4787f09d335
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue Jun 2 08:12:34 2026 -0700

    TIF lookup: match both <id>.tif and <category>/design_<id>.tif
    
    build-tif.py writes data/tif/<id>.tif (flat) but older rows used
    data/tif/<category>/design_<id>.tif — findTifOnDisk + the colorway source
    resolver now try both basenames, flat and one level deep. Verified locally:
    both conventions resolve to 200 image/jpeg.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
 server.js        | 17 ++++++++++++-----
 src/colorways.js | 15 ++++++++++-----
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/server.js b/server.js
index 360d109..cc7ef67 100644
--- a/server.js
+++ b/server.js
@@ -4159,14 +4159,21 @@ function findTifOnDisk(id) {
   }
   let hit = null;
   try {
-    const fname = `design_${id}.tif`;
-    const flat = path.join(TIF_DIR, fname);
-    if (fs.existsSync(flat)) hit = flat;
+    // Two naming conventions coexist: build-tif.py writes data/tif/<id>.tif
+    // (flat), while older rows used data/tif/<category>/design_<id>.tif.
+    const names = [`${id}.tif`, `design_${id}.tif`];
+    for (const n of names) {
+      const flat = path.join(TIF_DIR, n);
+      if (fs.existsSync(flat)) { hit = flat; break; }
+    }
     if (!hit && fs.existsSync(TIF_DIR)) {
+      outer:
       for (const ent of fs.readdirSync(TIF_DIR, { withFileTypes: true })) {
         if (!ent.isDirectory()) continue;
-        const cand = path.join(TIF_DIR, ent.name, fname);
-        if (fs.existsSync(cand)) { hit = cand; break; }
+        for (const n of names) {
+          const cand = path.join(TIF_DIR, ent.name, n);
+          if (fs.existsSync(cand)) { hit = cand; break outer; }
+        }
       }
     }
   } catch { /* non-fatal */ }
diff --git a/src/colorways.js b/src/colorways.js
index 87ad322..8c92f7d 100644
--- a/src/colorways.js
+++ b/src/colorways.js
@@ -69,14 +69,19 @@ function resolveSrcTifLocal(srcId) {
   // data/designs.json carries no tif_path — so this is the reliable path).
   const tifRoot = path.join(__dirname, '..', 'data', 'tif');
   try {
-    const fname = `design_${parseInt(srcId, 10)}.tif`;
-    const flat2 = path.join(tifRoot, fname);
-    if (fs.existsSync(flat2)) return flat2;
+    // build-tif.py writes <id>.tif (flat); older rows used <cat>/design_<id>.tif.
+    const names = [`${parseInt(srcId, 10)}.tif`, `design_${parseInt(srcId, 10)}.tif`];
+    for (const n of names) {
+      const flat2 = path.join(tifRoot, n);
+      if (fs.existsSync(flat2)) return flat2;
+    }
     if (fs.existsSync(tifRoot)) {
       for (const ent of fs.readdirSync(tifRoot, { withFileTypes: true })) {
         if (!ent.isDirectory()) continue;
-        const cand = path.join(tifRoot, ent.name, fname);
-        if (fs.existsSync(cand)) return cand;
+        for (const n of names) {
+          const cand = path.join(tifRoot, ent.name, n);
+          if (fs.existsSync(cand)) return cand;
+        }
       }
     }
   } catch (e) { /* non-fatal */ }

← 0f9c57a docs: TIF publish-gate review — rule unenforced + contradict  ·  back to Wallco Ai  ·  Add pilot-build-tifs.py (PG-drift-proof TIF builder via by-i d668131 →