mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 00:00:26 +00:00
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.
65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
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;
|
||
});
|