[object Object]

← back to AsSeenInMovies

asseeninmovies: GET /api/movies/random + /api/people/random — JSON random-row companions to the /random/* redirects. 60s cache. 65/65.

0898544eed58491efb3599dad7b324b860c325a7 · 2026-05-13 07:01:53 -0700 · SteveStudio2

Files touched

Diff

commit 0898544eed58491efb3599dad7b324b860c325a7
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Wed May 13 07:01:53 2026 -0700

    asseeninmovies: GET /api/movies/random + /api/people/random — JSON random-row companions to the /random/* redirects. 60s cache. 65/65.
---
 server.js | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/server.js b/server.js
index 615a629..f406d8c 100644
--- a/server.js
+++ b/server.js
@@ -92,6 +92,8 @@ app.get('/api', (_req, res) => {
       'GET /api/spotted':        'Verified SPOTTED placements (limit ≤ 200, optional category=…)',
       'GET /api/spotted/stats':  'Aggregate counts (pending/live/rejected/submitted_7d/films/brands/categories)',
       'GET /api/spotted/random': 'A single random verified SPOTTED placement (with movie context)',
+      'GET /api/movies/random':  'A single random poster-having movie',
+      'GET /api/people/random':  'A single random headshot-having person',
       'GET /api/ingest/status':  'Background-ingest queue depth (admin-ish; safe to expose)',
     },
     public_data_only: true,
@@ -724,6 +726,25 @@ app.get('/api/spotted', async (req, res) => {
 // JSON stats — same numbers the /spotted gallery + /spotted/queue strips
 // render, exposed as a single small API. Useful for the status-loop tail
 // monitor and any external dashboard. No auth needed — public counts only.
+// /api/movies/random + /api/people/random — JSON companions to the /random/*
+// redirects. Lightweight, 60s cache. Used by widgets that want a row inline.
+app.get('/api/movies/random', async (_req, res) => {
+  try {
+    const r = await pool.query(`SELECT id, title, release_year, poster_url FROM asim_movies WHERE poster_url IS NOT NULL ORDER BY random() LIMIT 1`);
+    if (!r.rows[0]) return res.status(404).json({ error: 'no-poster-yet' });
+    res.setHeader('Cache-Control', 'public, max-age=60, stale-while-revalidate=120');
+    res.json({ movie: r.rows[0] });
+  } catch (e) { res.status(500).json({ error: e.message }); }
+});
+app.get('/api/people/random', async (_req, res) => {
+  try {
+    const r = await pool.query(`SELECT id, full_name, headshot_url, primary_profession FROM asim_people WHERE headshot_url IS NOT NULL ORDER BY random() LIMIT 1`);
+    if (!r.rows[0]) return res.status(404).json({ error: 'no-headshot-yet' });
+    res.setHeader('Cache-Control', 'public, max-age=60, stale-while-revalidate=120');
+    res.json({ person: r.rows[0] });
+  } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
 // /api/spotted/random — JSON companion to /random/movie /random/person.
 // Pulls a single verified SPOTTED row at random. Useful for widgets that
 // want to feature "a placement from the catalog" inline. 60s cache.

← 6257501 asim smoke +2 ItemList checks (/movies + /people). 65/65.  ·  back to AsSeenInMovies  ·  asim /healthz Cache-Control: no-store (liveness should alway e67d0fe →