feat: 更新 ESLint 配置以放宽不安全参数传递的限制;在 API 查询中添加 Bili-Auth 支持;优化路由参数传递逻辑

This commit is contained in:
Megghy
2025-10-10 13:25:07 +08:00
parent a9453aa919
commit c9ec427692
6 changed files with 25 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
import type { APIRoot, PaginationResponse } from './api-models'
import { apiFail } from '@/data/constants'
import { cookie } from './account'
import { useBiliAuth } from '@/store/useBiliAuth';
export async function QueryPostAPI<T>(
urlString: string,
@@ -57,6 +58,10 @@ async function QueryPostAPIWithParamsInternal<T>(
h[header[0]] = header[1]
})
if (cookie.value.cookie) h.Authorization = `Bearer ${cookie.value.cookie}`
const biliAuth = useBiliAuth();
if (biliAuth.currentToken) {
h['Bili-Auth'] = biliAuth.currentToken;
}
// 当使用FormData时不手动设置Content-Type让浏览器自动添加boundary
if (!(body instanceof FormData)) {
@@ -117,6 +122,10 @@ async function QueryGetAPIInternal<T>(
if (cookie.value.cookie) {
h.Authorization = `Bearer ${cookie.value.cookie}`
}
const biliAuth = useBiliAuth();
if (biliAuth.currentToken) {
h['Bili-Auth'] = biliAuth.currentToken;
}
return await QueryAPIInternal<T>(url, { method: 'get', headers: h })
} catch (err) {
console.log(`url:${urlString}, error:${err}`)