feat: expose media playback routes

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-05-15 17:43:53 +07:00
parent b00def2d4d
commit 94e497b7a6
2 changed files with 119 additions and 0 deletions

51
src/routes/mediaRoutes.ts Normal file
View File

@@ -0,0 +1,51 @@
import type { Router } from "express";
import express from "express";
import { AppError } from "../errors";
import type { MediaController } from "../media/mediaController";
export type MediaRouteController = Pick<
MediaController,
"getState" | "queue" | "skip" | "stop"
>;
export function createMediaRoutes(controller: MediaRouteController): Router {
const router = express.Router();
router.get("/media/status", (_req, res, next) => {
try {
res.json(controller.getState());
} catch (error) {
next(error);
}
});
router.post("/media/queue", async (req, res, next) => {
try {
const { source } = req.body as { source?: string };
if (!source) {
throw new AppError("Media source is required", "MISSING_MEDIA_SOURCE", 400);
}
res.json(await controller.queue(source));
} catch (error) {
next(error);
}
});
router.post("/media/skip", async (_req, res, next) => {
try {
res.json(await controller.skip());
} catch (error) {
next(error);
}
});
router.post("/media/stop", async (_req, res, next) => {
try {
res.json(await controller.stop());
} catch (error) {
next(error);
}
});
return router;
}