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.
This commit is contained in:
dasemu committed 2026-08-24 04:53:12 +02:00
1 parent 7f3e6cc839
commit 99a903f6e1
20 files changed
+275 -97

No files matched your search

+28 -8
View File
@@ -1,11 +1,13 @@
import { Router } from "express";
import { config } from "../config.js";
import { generateStoriesWithGemini } from "../gemini.js";
import { addRating } from "../ratingStore.js";
import { RatingInputSchema } from "../ratingSchema.js";
import { getLatestStories, saveDailyStories } from "../storyStore.js";
export const storiesRouter = Router();
/** GET /api/stories: devuelve el ultimo lote generado, o 204 si no hay ninguno todavia. */
/** GET /api/stories: returns the latest generated batch, or 204 if none exists yet. */
storiesRouter.get("/stories", async (_req, res) => {
const latest = await getLatestStories();
if (!latest) {
@@ -17,15 +19,33 @@ storiesRouter.get("/stories", async (_req, res) => {
});
/**
* POST /api/admin/generate: dispara manualmente una generacion con Gemini.
* Requiere header "x-admin-token" que coincida con ADMIN_TOKEN.
* Pensado para pruebas manuales; la generacion diaria real la dispara el
* systemd timer llamando al script generateDaily.
* POST /api/stories/:id/ratings: records a player's voluntary 1-5 difficulty
* rating for a story once the round is over. Open endpoint, no auth — this
* is a low-stakes, best-effort signal used later by the reclassification
* script, not a security-sensitive write. Works for any story id, including
* ones from the default set embedded in the frontend (the backend doesn't
* need to know a story to accept a rating for it).
*/
storiesRouter.post("/stories/:id/ratings", async (req, res) => {
const parsed = RatingInputSchema.safeParse(req.body);
if (!parsed.success) {
res.status(400).json({ error: "invalid rating" });
return;
}
await addRating(req.params.id, parsed.data.rating);
res.status(204).end();
});
/**
* POST /api/admin/generate: manually triggers a generation run with Gemini.
* Requires an "x-admin-token" header matching ADMIN_TOKEN.
* Meant for manual testing; the real daily generation is triggered by the
* systemd timer calling the generateDaily script.
*/
storiesRouter.post("/admin/generate", async (req, res) => {
const token = req.header("x-admin-token");
if (!token || token !== config.adminToken) {
res.status(401).json({ error: "token invalido" });
res.status(401).json({ error: "invalid token" });
return;
}
@@ -36,7 +56,7 @@ storiesRouter.post("/admin/generate", async (req, res) => {
const saved = await saveDailyStories(stories);
res.json(saved);
} catch (err) {
console.error("Error generando historias:", err);
res.status(500).json({ error: "fallo la generacion", detail: String(err) });
console.error("Error generating stories:", err);
res.status(500).json({ error: "generation failed", detail: String(err) });
}
});