Files
NapCatQQ/packages/napcat-webui-frontend/src/utils/request.ts
手瓜一十雪 8eb1aa2fb4 Refactor GitHub tag fetching and mirror management
Replaces legacy tag fetching logic in napcat-common with a new mirror.ts module that centralizes GitHub mirror configuration, selection, and tag retrieval. Updates helper.ts to use the new mirror system and semver comparison, and exports compareSemVer for broader use. Updates workflows and scripts to generate and propagate build version information, and improves build status comment formatting for PRs. Also updates release workflow to use a new OpenAI key and model.
2026-01-03 14:42:24 +08:00

65 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import axios from 'axios';
import key from '@/const/key';
export const serverRequest = axios.create({
timeout: 30000, // 30秒获取版本列表可能较慢
});
export const request = axios.create({
timeout: 10000,
});
export const requestServerWithFetch = async (
url: string,
options: RequestInit
) => {
const token = localStorage.getItem(key.token);
if (token) {
options.headers = {
...options.headers,
Authorization: `Bearer ${JSON.parse(token)}`,
};
}
const baseURL = '/api';
const response = await fetch(baseURL + url, options);
return response;
};
serverRequest.interceptors.request.use((config) => {
const baseURL = '/api';
config.baseURL = baseURL;
const token = localStorage.getItem(key.token);
if (token) {
config.headers['Authorization'] = `Bearer ${JSON.parse(token)}`;
}
return config;
});
serverRequest.interceptors.response.use((response) => {
// 如果是流式传输的文件
if (response.headers['content-type'] === 'application/octet-stream') {
return response;
}
if (response.data.code !== 0) {
if (response.data.message === 'Unauthorized') {
const token = localStorage.getItem(key.token);
if (token && JSON.parse(token)) {
localStorage.removeItem(key.token);
window.location.reload();
}
}
throw new Error(response.data.message);
}
return response;
});