feat: 增加环境切换

This commit is contained in:
R524809
2026-10-19 17:49:19 +08:00
parent 997042789d
commit fe1074e3f0
21 changed files with 968 additions and 123 deletions
+16
View File
@@ -1,4 +1,5 @@
import { getApiConfig } from '../config/api';
import { beginApiWrite } from './api-activity';
import {
ApiRequestError,
requestApi,
@@ -30,6 +31,21 @@ const blocked = new Set([
export async function apiRequest<T>(
path: string,
options: RequestOptions & { auth?: 'required' | 'none' } = {},
): Promise<T> {
const finish =
options.upload || (options.method && options.method !== 'GET')
? beginApiWrite()
: undefined;
try {
return await performApiRequest<T>(path, options);
} finally {
finish?.();
}
}
async function performApiRequest<T>(
path: string,
options: RequestOptions & { auth?: 'required' | 'none' } = {},
): Promise<T> {
// Authorization 由会话层统一提供;公开请求不附带调用方误传的凭证。
const header = Object.fromEntries(