Fix Fastify Stremio routes: wildcard must be last path segment.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jos Vooges | STH 2026-08-25 00:55:20 +02:00
parent f6da966a92
commit 29595dd98f

View file

@ -24,13 +24,16 @@ const MANIFEST = {
export async function registerStremioRoutes(app: FastifyInstance, config: Config) { export async function registerStremioRoutes(app: FastifyInstance, config: Config) {
const playback = new PlaybackService(config); const playback = new PlaybackService(config);
app.options("/stremio/*", async (_request, reply) => { app.addHook("onRequest", async (request, reply) => {
if (!request.url.startsWith("/stremio/")) return;
reply.header("Access-Control-Allow-Origin", "*");
if (request.method === "OPTIONS") {
reply reply
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, OPTIONS") .header("Access-Control-Allow-Methods", "GET, OPTIONS")
.header("Access-Control-Allow-Headers", "Content-Type") .header("Access-Control-Allow-Headers", "Content-Type")
.status(204) .status(204)
.send(); .send();
}
}); });
app.get("/stremio/:token/manifest.json", async (request, reply) => { app.get("/stremio/:token/manifest.json", async (request, reply) => {
@ -39,17 +42,21 @@ export async function registerStremioRoutes(app: FastifyInstance, config: Config
if (!userId) { if (!userId) {
return reply.status(401).send({ error: "Invalid addon token" }); return reply.status(401).send({ error: "Invalid addon token" });
} }
reply.header("Access-Control-Allow-Origin", "*");
return MANIFEST; return MANIFEST;
}); });
app.get("/stremio/:token/catalog/:type/:id/*.json", async (request, reply) => { // Stremio catalog with extras: /catalog/movie/movies/search=matrix.json
const { token, type, id } = request.params as { token: string; type: string; id: string }; app.get("/stremio/:token/catalog/:type/:id/*", async (request, reply) => {
const { token, type, id } = request.params as {
token: string;
type: string;
id: string;
"*": string;
};
const userId = await validateAddonToken(token); const userId = await validateAddonToken(token);
if (!userId) { if (!userId) {
return reply.status(401).send({ error: "Invalid addon token" }); return reply.status(401).send({ error: "Invalid addon token" });
} }
reply.header("Access-Control-Allow-Origin", "*");
const extra = (request.params as { "*": string })["*"] ?? ""; const extra = (request.params as { "*": string })["*"] ?? "";
const search = parseExtraSearch(extra); const search = parseExtraSearch(extra);
@ -68,7 +75,6 @@ export async function registerStremioRoutes(app: FastifyInstance, config: Config
if (!userId) { if (!userId) {
return reply.status(401).send({ error: "Invalid addon token" }); return reply.status(401).send({ error: "Invalid addon token" });
} }
reply.header("Access-Control-Allow-Origin", "*");
if (type === "movie") { if (type === "movie") {
return { metas: await getMovieCatalog(id, config) }; return { metas: await getMovieCatalog(id, config) };
@ -85,7 +91,6 @@ export async function registerStremioRoutes(app: FastifyInstance, config: Config
if (!userId) { if (!userId) {
return reply.status(401).send({ error: "Invalid addon token" }); return reply.status(401).send({ error: "Invalid addon token" });
} }
reply.header("Access-Control-Allow-Origin", "*");
if (type === "movie") { if (type === "movie") {
const meta = await getMovieMeta(id); const meta = await getMovieMeta(id);
@ -104,7 +109,6 @@ export async function registerStremioRoutes(app: FastifyInstance, config: Config
if (!userId) { if (!userId) {
return reply.status(401).send({ error: "Invalid addon token" }); return reply.status(401).send({ error: "Invalid addon token" });
} }
reply.header("Access-Control-Allow-Origin", "*");
const streams = await getStreams(type, id, userId, playback); const streams = await getStreams(type, id, userId, playback);
return { streams }; return { streams };