leaf-document-web/src/plugins/api.ts

59 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-12-04 14:26:11 +00:00
import { DocumentsApi, Configuration, LibrariesApi } from "../openapi";
2023-12-04 13:33:37 +00:00
2023-12-04 14:26:11 +00:00
// import axios from "axios";
// import router from "@/router";
import {useUserStore} from "@/store/user";
2023-12-04 13:33:37 +00:00
// // const config = useConfigStore()
// import config from "@/plugins/config"
// instance.interceptors.request.use(
// (config) => {
// if (config.headers === undefined) {
// // config.headers = {};
// }
// config.headers["Accept"] = "application/json";
// // @ts-ignore
// if (process.env.NODE_ENV === "development") {
// // user.jwt_token 取中间
// config.headers["X-Jwt-Payload"] = user.jwt_token?.split(".")[1]
// } else {
// config.headers["Authorization"] = "Bearer " + user.jwt_token;
// }
// return config;
// },
// (error) => {
// console.error("axios request error", error);
// return Promise.reject(error);
// }
// );
// instance.interceptors.response.use(
// (res) => {
// return Promise.resolve(res);
// },
// (error) => {
// console.error("axios response error", error);
// return Promise.reject(error);
// }
// );
// export default instance;
2023-12-04 14:26:11 +00:00
const userStore = useUserStore()
2023-12-04 13:33:37 +00:00
const conf = new Configuration
conf.basePath = "https://document.awa.im/api"
2023-12-04 14:26:11 +00:00
conf.apiKey = "Bearer " + userStore.jwt_token
const document = new DocumentsApi(conf);
const library = new LibrariesApi(conf);
2023-12-04 13:33:37 +00:00
2023-12-04 14:26:11 +00:00
export {
2023-12-07 14:52:49 +00:00
document, library, conf
2023-12-04 14:26:11 +00:00
}