cvsa/packages/backend/root.ts
alikia2x a2b55d0900
feat: root path for API
improve: the GET video snapshots API
2025-03-31 05:07:22 +08:00

31 lines
821 B
TypeScript

import { getSingerForBirthday, pickSinger, pickSpecialSinger, type Singer } from "./singers.ts";
import { VERSION } from "./main.ts";
import { createHandlers } from "./utils.ts";
export const rootHandler = createHandlers((c) => {
let singer: Singer | Singer[] | null = null;
const shouldShowSpecialSinger = Math.random() < 0.016;
if (getSingerForBirthday().length !== 0){
singer = getSingerForBirthday();
for (const s of singer) {
delete s.birthday;
s.message = `${s.name}生日快乐~`
}
}
else if (shouldShowSpecialSinger) {
singer = pickSpecialSinger();
}
else {
singer = pickSinger();
}
return c.json({
"project": {
"name": "中V档案馆",
"motto": "一起唱吧,心中的歌!"
},
"status": 200,
"version": VERSION,
"time": Date.now(),
"singer": singer
})
})