diff options
| author | dax <me@dax.ist> | 2026-08-04 06:55:33 +0000 |
|---|---|---|
| committer | dax <me@dax.ist> | 2026-08-04 06:55:33 +0000 |
| commit | a32e5b41b785e7334af6f796adc6a1b5216a5cc9 (patch) | |
| tree | c64639f2ae502ad80a071fe8a18f2322cc64ae13 /server.mjs | |
| parent | 6e64a126967a70f67c33f60fa438fa67023ca419 (diff) | |
pathways: native-aspect free-form mosaic, no teleports (walk to next unplaced), arrows on every photo, arrows inside tiles, drop path text
Diffstat (limited to 'server.mjs')
| -rw-r--r-- | server.mjs | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -20,7 +20,7 @@ const MIN_PATH = 3 const pool = mysql.createPool(DB) -const THUMB_SIZE = "720x720_fit" +const THUMB_SIZE = "1280x1024_fit" const BIG_SIZE = "1920x1200_fit" const thumb = (hash, size = THUMB_SIZE) => { if (!hash) return null @@ -33,7 +33,7 @@ let state = null async function load() { const [photos] = await pool.query( `SELECT p.id, p.photo_title, p.photo_year, p.photo_month, p.photo_day, - f.file_hash + f.file_hash, f.file_width, f.file_height FROM photos p JOIN files f ON f.photo_id = p.id AND f.file_primary = 1 AND f.file_missing = 0 WHERE p.deleted_at IS NULL @@ -51,6 +51,8 @@ async function load() { date: p.photo_year ? `${p.photo_year}-${String(p.photo_month || 1).padStart(2, "0")}-${String(p.photo_day || 1).padStart(2, "0")}` : "", + w: p.file_width || 0, + h: p.file_height || 0, }) photoOrder.push(p.id) } @@ -123,10 +125,15 @@ async function load() { const step = used.get(p.key) || 0 used.set(p.key, step + 1) const idx = p.ids.indexOf(pid) + const cyc = p.ids + const start = (idx + 1 + step) % cyc.length + const walk = [] + for (let k = 0; k < 60 && walk.length < cyc.length; k++) walk.push(cyc[(start + k) % cyc.length]) list.push({ dir: DIRS[i], path: { type: p.type, name: p.name, count: p.count }, - nextId: p.ids[(idx + 1 + step) % p.ids.length], + nextId: cyc[start], + walk, }) } exits.set(pid, list) @@ -162,7 +169,7 @@ function json(res, code, data) { async function photoConnections(id) { const [ph] = await pool.query( `SELECT p.id, p.photo_title, p.photo_year, p.photo_month, p.photo_day, - f.file_hash + f.file_hash, f.file_width, f.file_height FROM photos p JOIN files f ON f.photo_id = p.id AND f.file_primary = 1 AND f.file_missing = 0 WHERE p.id = ?`, @@ -207,6 +214,8 @@ async function photoConnections(id) { full: thumb(p.file_hash, BIG_SIZE), title: p.photo_title || "", date: p.photo_year ? `${p.photo_year}-${String(p.photo_month || 1).padStart(2, "0")}-${String(p.photo_day || 1).padStart(2, "0")}` : "", + w: p.file_width || 0, + h: p.file_height || 0, }, connections: conns, } @@ -232,9 +241,15 @@ const server = http.createServer(async (req, res) => { const id = Number(exitMatch[1]) const e = state.exits.get(id) if (!e) return json(res, 404, { error: "not found" }) + const photos = {} + for (const x of e) for (const wid of x.walk) { + const ph = state.byId.get(wid) + if (ph) photos[wid] = ph + } return json(res, 200, { photo: state.byId.get(id), - exits: e.map((x) => ({ dir: x.dir, path: x.path, next: state.byId.get(x.nextId) })), + exits: e.map((x) => ({ dir: x.dir, path: x.path, next: state.byId.get(x.nextId), walk: x.walk })), + photos, }) } const photoMatch = path.match(/^\/api\/photo\/(\d+)$/) |
