← back to Wallco Ai
elements/img: fall back to source tile by-id when baked derivative missing (data/elements was a dangling symlink on prod)
dfe2bceaee527b5f786297a70dfd6f5ec6494c8c · 2026-05-30 12:08:25 -0700 · Steve Abrams
Files touched
Diff
commit dfe2bceaee527b5f786297a70dfd6f5ec6494c8c
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Sat May 30 12:08:25 2026 -0700
elements/img: fall back to source tile by-id when baked derivative missing (data/elements was a dangling symlink on prod)
---
server.js | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/server.js b/server.js
index 46ba167..d1a0dfe 100644
--- a/server.js
+++ b/server.js
@@ -2579,10 +2579,21 @@ app.get('/api/admin/mid-heal-preview/sample', (req, res) => {
// Serve baked element derivatives. These live outside the public
// /designs/img/ tree so they can be cleared without touching source tiles.
-app.use('/elements/img', express.static(
- path.join(__dirname, 'data', 'elements'),
- { maxAge: '30d' }
-));
+app.get('/elements/img/:file', (req, res) => {
+ // Serve the baked derivative if present; otherwise fall back to the source
+ // tile by-id (data/elements can be cleared/symlinked-away without touching
+ // source tiles, so a missing bake must degrade to the live image, never 404).
+ const file = req.params.file;
+ if (!/^[A-Za-z0-9._-]+$/.test(file)) return res.status(404).end();
+ const fp = path.join(__dirname, 'data', 'elements', file);
+ if (fs.existsSync(fp)) {
+ res.set('Cache-Control', 'public, max-age=2592000');
+ return res.sendFile(fp);
+ }
+ const m = String(file).match(/^(\d+)_/);
+ if (m) return res.redirect(302, '/designs/img/by-id/' + m[1]);
+ return res.status(404).end();
+});
app.get('/api/admin/elements/items', (req, res) => {
if (!isAdmin(req)) return res.status(404).json({ error: 'not found' });
← be08cbc fix(room-mockups): resolve ROOT from __file__ not Path.home(
·
back to Wallco Ai
·
cactus-curator: bulk Publish now animates published cards ou 1ac6616 →