forked from LeetCode-OpenSource/vscode-leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpUtils.ts
28 lines (26 loc) · 959 Bytes
/
httpUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import axios, { AxiosRequestConfig, AxiosPromise } from "axios";
import { omit } from "lodash";
import { globalState } from "../globalState";
import { DialogType, promptForOpenOutputChannel } from "./uiUtils";
const referer = "vscode-lc-extension";
export function LcAxios<T = any>(path: string, settings?: AxiosRequestConfig): AxiosPromise<T> {
const cookie = globalState.getCookie();
if (!cookie) {
promptForOpenOutputChannel(
`Failed to obtain the cookie. Please log in again.`,
DialogType.error
);
return Promise.reject("Failed to obtain the cookie.");
}
return axios(path, {
headers: {
referer: referer,
"content-type": "application/json",
cookie,
...(settings && settings.headers),
},
xsrfCookieName: "csrftoken",
xsrfHeaderName: "X-CSRFToken",
...(settings && omit(settings, "headers")),
});
}