[object Object]

← back to Wallco Ai

TIF resolution: PG-independent disk lookup by design_<id>.tif

4ef783f48e708d4c8ea2f2f9b26fd6202544be24 · 2026-06-02 08:08:22 -0700 · Steve Abrams

Prod's all_designs is sparse (~350 rows) and data/designs.json carries no
tif_path, so the PG-based TIF lookup never resolved on prod (hires route always
302-fell-back). Add findTifOnDisk(id) — scans data/tif/<category>/design_<id>.tif
and caches the hit/miss — used as a fallback in both the /designs/hires/:id
route and the colorway recolor source resolver. Now the full-res TIF is found
whenever the file is present on disk, regardless of PG drift.

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

Files touched

Diff

commit 4ef783f48e708d4c8ea2f2f9b26fd6202544be24
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue Jun 2 08:08:22 2026 -0700

    TIF resolution: PG-independent disk lookup by design_<id>.tif
    
    Prod's all_designs is sparse (~350 rows) and data/designs.json carries no
    tif_path, so the PG-based TIF lookup never resolved on prod (hires route always
    302-fell-back). Add findTifOnDisk(id) — scans data/tif/<category>/design_<id>.tif
    and caches the hit/miss — used as a fallback in both the /designs/hires/:id
    route and the colorway recolor source resolver. Now the full-res TIF is found
    whenever the file is present on disk, regardless of PG drift.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
 server.js        | 34 +++++++++++++++++++++++++++++++++-
 src/colorways.js | 28 ++++++++++++++++++++++------
 2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/server.js b/server.js
index 823e594..360d109 100644
--- a/server.js
+++ b/server.js
@@ -4144,6 +4144,36 @@ app.get('/designs/img/by-id/:id', (req, res) => {
   return res.status(404).end();
 });
 
+// Find a design's full-size TIF on disk by the canonical filename convention
+// (data/tif/<category>/design_<id>.tif) WITHOUT relying on PG. Prod's
+// all_designs is sparse (~350 rows) and data/designs.json carries no tif_path,
+// so a PG lookup can't locate TIFs on prod even when the files are present.
+// Scans the one-level category dirs under data/tif and caches the hit (or the
+// miss, as null) so a repeat request is O(1).
+const TIF_DIR = path.join(__dirname, 'data', 'tif');
+const _tifByIdCache = new Map();
+function findTifOnDisk(id) {
+  if (_tifByIdCache.has(id)) {
+    const c = _tifByIdCache.get(id);
+    if (c === null || (c && fs.existsSync(c))) return c;
+  }
+  let hit = null;
+  try {
+    const fname = `design_${id}.tif`;
+    const flat = path.join(TIF_DIR, fname);
+    if (fs.existsSync(flat)) hit = flat;
+    if (!hit && fs.existsSync(TIF_DIR)) {
+      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; }
+      }
+    }
+  } catch { /* non-fatal */ }
+  _tifByIdCache.set(id, hit);
+  return hit;
+}
+
 // Resolve a stored asset path (tif_path / svg_path) to a real local file.
 // PG may carry a Mac2-absolute path that doesn't exist on prod (and vice-
 // versa); match on the `data/<kind>/…` suffix and re-root under __dirname.
@@ -4184,7 +4214,9 @@ app.get('/designs/hires/:id', (req, res) => {
     const sv = resolveAssetLocal(svgPath, 'svg');
     if (sv) { res.type('image/svg+xml'); return res.sendFile(sv); }
   }
-  const tifLocal = resolveAssetLocal(tifPath, 'tif');
+  // Resolve the TIF: PG path first (Mac2/prod prefix-translated), then a
+  // PG-independent disk lookup by design_<id>.tif (prod PG is sparse).
+  const tifLocal = resolveAssetLocal(tifPath, 'tif') || findTifOnDisk(id);
   if (!tifLocal) return res.redirect(302, byId);
   try {
     const cached = path.join(HIRES_DIR, id + '.jpg');
diff --git a/src/colorways.js b/src/colorways.js
index 9429348..87ad322 100644
--- a/src/colorways.js
+++ b/src/colorways.js
@@ -58,12 +58,28 @@ function resolveSrcTifLocal(srcId) {
       if (r) tif = r.split('\n')[0].trim();
     } catch (e) { /* table/col may not exist on this box */ }
   }
-  if (!tif) return null;
-  if (fs.existsSync(tif)) return tif;
-  const i = tif.indexOf('data/tif/');
-  if (i >= 0) { const local = path.join(__dirname, '..', tif.slice(i)); if (fs.existsSync(local)) return local; }
-  const flat = path.join(__dirname, '..', 'data', 'tif', path.basename(tif));
-  if (fs.existsSync(flat)) return flat;
+  if (tif) {
+    if (fs.existsSync(tif)) return tif;
+    const i = tif.indexOf('data/tif/');
+    if (i >= 0) { const local = path.join(__dirname, '..', tif.slice(i)); if (fs.existsSync(local)) return local; }
+    const flat = path.join(__dirname, '..', 'data', 'tif', path.basename(tif));
+    if (fs.existsSync(flat)) return flat;
+  }
+  // PG-independent disk lookup by the canonical filename (prod PG is sparse and
+  // 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;
+    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;
+      }
+    }
+  } catch (e) { /* non-fatal */ }
   return null;
 }
 

← 13bf818 audit: unpublish 17 dogs published with NULL tif_path (un-or  ·  back to Wallco Ai  ·  docs: TIF publish-gate review — rule unenforced + contradict 0f9c57a →