feat: 新增数据库

This commit is contained in:
2026-04-25 21:52:18 +08:00
parent 223845b0ed
commit abd1b03529
23 changed files with 1890 additions and 97 deletions
+18 -1
View File
@@ -1,5 +1,5 @@
import type { H3Event } from "h3";
import { deleteCookie, setCookie } from "h3";
import { createError, deleteCookie, getCookie, setCookie } from "h3";
/** 上游没有声明 session 过期时间时,本地登录态默认保留 3 天 */
const DEFAULT_AUTH_COOKIE_MAX_AGE = 60 * 60 * 24 * 3;
@@ -100,6 +100,23 @@ export const clearNewApiAuthCookies = (event: H3Event) => {
deleteCookie(event, NEWAPI_USER_ID_COOKIE, options);
};
/** 从本项目 httpOnly cookie 中读取 NewAPI 用户 ID,缺失或非法时统一视为未登录 */
export const getNewApiUserIdFromCookie = (event: H3Event): number => {
const userId = Number.parseInt(
getCookie(event, NEWAPI_USER_ID_COOKIE) ?? "",
10
);
if (!Number.isInteger(userId) || userId <= 0) {
throw createError({
statusCode: 401,
statusMessage: "未登录"
});
}
return userId;
};
/** 统一生成本站认证 cookie 选项,保证安全属性在两个 cookie 上一致 */
const buildAuthCookieOptions = (meta?: INewApiCookieMeta): CookieOptions => {
const options: CookieOptions = {