mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
✨ feat: 支持 Vercel 部署
This commit is contained in:
@@ -18,6 +18,8 @@ const serveHotApi = (port: number = config.PORT) => {
|
||||
}
|
||||
};
|
||||
|
||||
serveHotApi();
|
||||
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "docker") {
|
||||
serveHotApi(config.PORT);
|
||||
}
|
||||
|
||||
export default serveHotApi;
|
||||
|
||||
@@ -14,6 +14,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
let allRoutePath: Array<string> = [];
|
||||
const routersDirName: string = "routes";
|
||||
|
||||
// 排除路由
|
||||
const excludeRoutes: Array<string> = ["52pojie", "hostloc"];
|
||||
|
||||
// 建立完整目录路径
|
||||
const routersDirPath = path.join(__dirname, routersDirName);
|
||||
|
||||
@@ -47,6 +50,10 @@ if (fs.existsSync(routersDirPath) && fs.statSync(routersDirPath).isDirectory())
|
||||
// 注册全部路由
|
||||
for (let index = 0; index < allRoutePath.length; index++) {
|
||||
const router = allRoutePath[index];
|
||||
// 是否处于排除名单
|
||||
if (excludeRoutes.includes(router)) {
|
||||
continue;
|
||||
}
|
||||
const listApp = app.basePath(`/${router}`);
|
||||
// 返回榜单
|
||||
listApp.get("/", async (c) => {
|
||||
@@ -85,6 +92,16 @@ for (let index = 0; index < allRoutePath.length; index++) {
|
||||
...listData,
|
||||
});
|
||||
});
|
||||
// 请求方式错误
|
||||
listApp.all("*", (c) =>
|
||||
c.json(
|
||||
{
|
||||
code: 405,
|
||||
message: "Method Not Allowed",
|
||||
},
|
||||
405,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 获取全部路由
|
||||
@@ -93,10 +110,20 @@ app.get("/all", (c) =>
|
||||
{
|
||||
code: 200,
|
||||
count: allRoutePath.length,
|
||||
routes: allRoutePath.map((path) => ({
|
||||
name: path,
|
||||
path: `/${path}`,
|
||||
})),
|
||||
routes: allRoutePath.map((path) => {
|
||||
// 是否处于排除名单
|
||||
if (excludeRoutes.includes(path)) {
|
||||
return {
|
||||
name: path,
|
||||
path: null,
|
||||
message: "该接口暂时下线",
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: path,
|
||||
path: `/${path}`,
|
||||
};
|
||||
}),
|
||||
},
|
||||
200,
|
||||
),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import crypto from "crypto";
|
||||
|
||||
/**
|
||||
@@ -13,7 +14,7 @@ const getWereadID = (bookId: string) => {
|
||||
// 取哈希结果的前三个字符作为初始值
|
||||
let strSub = str.substring(0, 3);
|
||||
// 判断书籍 ID 的类型并进行转换
|
||||
let fa;
|
||||
let fa: (string | any[])[];
|
||||
if (/^\d*$/.test(bookId)) {
|
||||
// 如果书籍 ID 只包含数字,则将其拆分成长度为 9 的子字符串,并转换为十六进制表示
|
||||
const chunks = [];
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user