Files
dasemu 99a903f6e1 Add player difficulty ratings, drop hint system, use Peninsular Spanish in Gemini prompt
Players can now submit a voluntary 1-5 difficulty rating after a story
ends (POST /api/stories/:id/ratings), stored in data/ratings.json. A new
reclassifyDifficulty script (wired to a weekly systemd timer) averages
those ratings and adjusts a story's difficulty band once it has enough
votes. The progressive hint system is removed end-to-end (schema, Gemini
prompt/response schema, generation instructions), and the Gemini prompt
is rewritten in Peninsular Spanish with an explicit instruction to
generate story content in Spain Spanish rather than any LatAm variant.
Also translates remaining Spanish code comments/error strings to English
and updates the backend README and systemd units accordingly.
2026-08-24 04:53:12 +02:00

52 lines
2.0 KiB
Markdown

# Backend — Sí, no, o indiferente
Node/Express (TypeScript) API that serves the "updated" story deck and
regenerates it once a day by calling the Gemini API.
## Endpoints
- `GET /api/health` — health check.
- `GET /api/stories` — latest generated story batch. `204` if none has been
generated yet (the client should fall back to its default set in that
case).
- `POST /api/admin/generate` — triggers a manual generation with Gemini.
Requires an `x-admin-token` header matching `ADMIN_TOKEN`.
- `POST /api/stories/:id/ratings` — records a player's voluntary 1-5
difficulty rating for a story (`{ "rating": 1-5 }` body). Open endpoint,
no auth required. Works for any story id, including ones from the
frontend's embedded default set.
## Development
```bash
npm install
cp .env.example .env # fill in GEMINI_API_KEY and ADMIN_TOKEN
npm run dev # http://localhost:8787
npm run generate # generates a new batch by hand (calls Gemini for real)
npm run reclassify # reclassifies difficulty from collected ratings by hand
```
## Production
```bash
npm run build
npm start # runs dist/index.js
npm run generate:built # runs dist/scripts/generateDaily.js (used by the systemd timer)
npm run reclassify:built # runs dist/scripts/reclassifyDifficulty.js (used by the systemd timer)
```
See the example unit files in `../deploy/` for the systemd + nginx setup.
## Storage
Generated stories are stored as plain JSON files in `data/` (configurable
via `DATA_DIR`): one file per day (`YYYY-MM-DD.json`) plus `latest.json`,
which is what `GET /api/stories` serves. There's no database — at this
volume (5 stories/day) a JSON file with atomic writes is more than enough.
Player difficulty ratings are appended to `data/ratings.json` as they come
in. The `reclassifyDifficulty` script (run periodically via
`story-reclassify.timer`) averages the ratings for each story and, once a
story has at least `MIN_RATINGS_FOR_RECLASSIFICATION` votes, updates its
difficulty band in `latest.json` if the average points to a different one.