diff options
author | crupest <crupest@outlook.com> | 2021-01-11 21:58:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 21:58:32 +0800 |
commit | 5f08a5afe39fb680a14982255d366335bcef5d6e (patch) | |
tree | 9deed1bab5913de2e2e31e1b7a8f14e7ee699cf8 /FrontEnd/src/app/http/common.ts | |
parent | 6d30c089c02591ce2f57cf22fe0c41c17c62fbc3 (diff) | |
parent | 21ee6d4b78566a857559c5e393ae85731d380092 (diff) | |
download | timeline-5f08a5afe39fb680a14982255d366335bcef5d6e.tar.gz timeline-5f08a5afe39fb680a14982255d366335bcef5d6e.tar.bz2 timeline-5f08a5afe39fb680a14982255d366335bcef5d6e.zip |
Merge pull request #206 from crupest/front-dev
Front development.
Diffstat (limited to 'FrontEnd/src/app/http/common.ts')
-rw-r--r-- | FrontEnd/src/app/http/common.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/FrontEnd/src/app/http/common.ts b/FrontEnd/src/app/http/common.ts index 54203d1a..0f46280c 100644 --- a/FrontEnd/src/app/http/common.ts +++ b/FrontEnd/src/app/http/common.ts @@ -1,7 +1,27 @@ -import { AxiosError, AxiosResponse } from "axios"; +import rawAxios, { AxiosError, AxiosResponse } from "axios"; export const apiBaseUrl = "/api"; +export const axios = rawAxios.create(); + +let _token: string | null = null; + +export function getHttpToken(): string | null { + return _token; +} + +export function setHttpToken(token: string | null): void { + _token = token; + + if (token == null) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + delete axios.defaults.headers.common["Authorization"]; + } else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; + } +} + export function base64(blob: Blob): Promise<string> { return new Promise<string>((resolve) => { const reader = new FileReader(); @@ -159,3 +179,7 @@ export function convertToBlobWithEtag(res: AxiosResponse<Blob>): BlobWithEtag { etag: (res.headers as Record<"etag", string>)["etag"], }; } + +export function extractEtag(res: AxiosResponse): string { + return (res.headers as Record<"etag", string>)["etag"]; +} |