mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-10 02:37:56 +08:00
update
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import axios from "axios";
|
||||
import { GlobalConf } from "../utils/type";
|
||||
|
||||
const baseUrl = '/hk_reporter/api/'
|
||||
import { GlobalConf, TokenResp } from "../utils/type";
|
||||
import { baseUrl } from './utils';
|
||||
|
||||
export async function getGlobalConf(): Promise<GlobalConf> {
|
||||
const res = await axios.get<GlobalConf>(`${baseUrl}global_conf`);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
export async function auth(token: string): Promise<TokenResp> {
|
||||
const res = await axios.get<TokenResp>(`${baseUrl}auth`, {params: {token}});
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
// import { useContext } from 'react';
|
||||
// import { LoginContext } from "../utils/context";
|
||||
|
||||
export const baseUrl = '/hk_reporter/api/'
|
||||
|
||||
// const loginStatus = useContext(LoginContext);
|
||||
axios.interceptors.request.use(function (config) {
|
||||
if (config.url && config.url.startsWith(baseUrl) && config.url !== `${baseUrl}auth`
|
||||
&& config.url !== `${baseUrl}global_conf`) {
|
||||
const token = sessionStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers['Authorization'] = `Bearer ${token}`;
|
||||
} else {
|
||||
throw new axios.Cancel('User not login');
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
})
|
||||
Reference in New Issue
Block a user