mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-05-17 22:17:30 +08:00
Update
This commit is contained in:
@@ -2,8 +2,6 @@ import { Router } from "express";
|
||||
import searchRouter from "./search";
|
||||
import detailRouter from "./detail";
|
||||
import doubanRouter from "./douban";
|
||||
import loginRouter from "./login";
|
||||
import playRecordsRouter from "./playrecords";
|
||||
import imageProxyRouter from "./image-proxy";
|
||||
|
||||
const router = Router();
|
||||
@@ -11,8 +9,6 @@ const router = Router();
|
||||
router.use("/search", searchRouter);
|
||||
router.use("/detail", detailRouter);
|
||||
router.use("/douban", doubanRouter);
|
||||
router.use("/login", loginRouter);
|
||||
router.use("/playrecords", playRecordsRouter);
|
||||
router.use("/image-proxy", imageProxyRouter);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post("/", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const masterPassword = process.env.PASSWORD;
|
||||
|
||||
// If no password is set in the environment, allow access.
|
||||
if (!masterPassword) {
|
||||
return res.json({ ok: true });
|
||||
}
|
||||
|
||||
const { password } = req.body;
|
||||
if (typeof password !== "string") {
|
||||
return res.status(400).json({ error: "密码不能为空" });
|
||||
}
|
||||
|
||||
const matched = password === masterPassword;
|
||||
|
||||
if (!matched) {
|
||||
return res.status(401).json({ ok: false, error: "密码错误" });
|
||||
}
|
||||
|
||||
return res.json({ ok: true });
|
||||
} catch (error) {
|
||||
return res.status(500).json({ error: "服务器错误" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { getAllPlayRecords, savePlayRecord } from "../services/db";
|
||||
import { PlayRecord } from "../types";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET all play records
|
||||
router.get("/", async (_req: Request, res: Response) => {
|
||||
try {
|
||||
const records = await getAllPlayRecords();
|
||||
res.json(records);
|
||||
} catch (err) {
|
||||
console.error("获取播放记录失败", err);
|
||||
res.status(500).json({ error: "Internal Server Error" });
|
||||
}
|
||||
});
|
||||
|
||||
// POST a new play record
|
||||
router.post("/", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { key, record }: { key: string; record: PlayRecord } = req.body;
|
||||
|
||||
if (!key || !record) {
|
||||
return res.status(400).json({ error: "Missing key or record" });
|
||||
}
|
||||
|
||||
// Basic validation
|
||||
if (!record.title || !record.source_name || record.index < 0) {
|
||||
return res.status(400).json({ error: "Invalid record data" });
|
||||
}
|
||||
|
||||
const [source, id] = key.split("+");
|
||||
if (!source || !id) {
|
||||
return res.status(400).json({ error: "Invalid key format" });
|
||||
}
|
||||
|
||||
// The user_id will be stripped and re-added in the service to ensure it's always 0
|
||||
const recordToSave: Omit<PlayRecord, "user_id"> = record;
|
||||
|
||||
await savePlayRecord(source, id, recordToSave);
|
||||
|
||||
res.status(201).json({ success: true });
|
||||
} catch (err) {
|
||||
console.error("保存播放记录失败", err);
|
||||
res.status(500).json({ error: "Internal Server Error" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user