[object Object]

← back to Dw Photo Capture

color-index: carry product_type through builder + both /apps/color-index and /apps/color-widen results (shop-by-color type checkboxes)

8112eafb41ed968c36d440a6476b4eadfaecec4d · 2026-07-17 10:29:42 -0700 · Steve Abrams

Files touched

Diff

commit 8112eafb41ed968c36d440a6476b4eadfaecec4d
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Fri Jul 17 10:29:42 2026 -0700

    color-index: carry product_type through builder + both /apps/color-index and /apps/color-widen results (shop-by-color type checkboxes)
---
 scripts/build-color-index.cjs | 6 ++++--
 server.js                     | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/build-color-index.cjs b/scripts/build-color-index.cjs
index 9a5bd9d..3b6a806 100644
--- a/scripts/build-color-index.cjs
+++ b/scripts/build-color-index.cjs
@@ -15,7 +15,7 @@
  * do a pure perceptual ΔE filter with no DB dependency at request time.
  *
  * Output: data/color-index.json  → { generated_at, count, items:[
- *   { h:"handle", t:"title", v:"vendor", x:"#rrggbb", l:LAB_L, a:LAB_A, b:LAB_B, i:"image_url" } ] }
+ *   { h:"handle", t:"title", v:"vendor", x:"#rrggbb", l:LAB_L, a:LAB_A, b:LAB_B, i:"image_url", p:"product_type" } ] }
  * Short keys keep the file small (~60k rows).
  *
  * Run where pg resolves (dwphoto's symlinked node_modules has it):
@@ -48,6 +48,7 @@ const OUT = path.join(__dirname, '..', 'data', 'color-index.json');
   const q = `
     SELECT DISTINCT ON (pc.handle)
       pc.handle, pc.title, pc.vendor, pc.hex, pc.lab_l, pc.lab_a, pc.lab_b,
+      sp.product_type,
       COALESCE(NULLIF(sp.image_url, ''), pc.image_url) AS image_url
     FROM product_colors pc
     JOIN shopify_products sp ON sp.handle = pc.handle
@@ -81,7 +82,8 @@ const OUT = path.join(__dirname, '..', 'data', 'color-index.json');
     l: Math.round(r.lab_l * 10) / 10,
     a: Math.round(r.lab_a * 10) / 10,
     b: Math.round(r.lab_b * 10) / 10,
-    i: r.image_url
+    i: r.image_url,
+    p: (r.product_type || '').slice(0, 40)
   }));
 
   const payload = {
diff --git a/server.js b/server.js
index 09443b6..0ea45e2 100644
--- a/server.js
+++ b/server.js
@@ -1015,7 +1015,8 @@ const appHandler = (req, res) => {
         within.sort((x, y) => x.de - y.de);          // nearest first
         const results = within.slice(0, k).map(w => ({
           handle: w.it.h, title: w.it.t, vendor: w.it.v,
-          hex: w.it.x, image: w.it.i, delta_e: Math.round(w.de * 10) / 10
+          hex: w.it.x, image: w.it.i, product_type: w.it.p || '',
+          delta_e: Math.round(w.de * 10) / 10
         }));
         return send(res, 200, {
           ok: true, hex, tolerance_pct: COLOR_INDEX_TOLERANCE_PCT,
@@ -1075,7 +1076,8 @@ const appHandler = (req, res) => {
         if (sel.length < min) sel = scored.slice(0, min); // thin band → expand to the nearest `min`
         const results = sel.slice(0, k).map(w => ({
           handle: w.it.h, title: w.it.t, vendor: w.it.v,
-          hex: w.it.x, image: w.it.i, delta_e: Math.round(w.de * 10) / 10
+          hex: w.it.x, image: w.it.i, product_type: w.it.p || '',
+          delta_e: Math.round(w.de * 10) / 10
         }));
         return send(res, 200, {
           ok: true, hex, tolerance_pct: ceil / 100, delta_e_ceiling: ceil, min,

← 0d6c355 color-widen: add min param — guarantee >=N results via neare  ·  back to Dw Photo Capture  ·  chore: version-up v1.5.0 (session close — shop-by-color prod a9c6a11 →