diff options
author | crupest <crupest@outlook.com> | 2020-12-21 17:33:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-21 17:33:16 +0800 |
commit | d960fdcfb79caf257fed6b68cc169a785003d965 (patch) | |
tree | 5aa5aaae61c2d179ae04bb026571e0028662d835 /FrontEnd/src/app/http | |
parent | caa9d638c8167a54e19344e6e4cea99da2b031ef (diff) | |
download | timeline-d960fdcfb79caf257fed6b68cc169a785003d965.tar.gz timeline-d960fdcfb79caf257fed6b68cc169a785003d965.tar.bz2 timeline-d960fdcfb79caf257fed6b68cc169a785003d965.zip |
...
Diffstat (limited to 'FrontEnd/src/app/http')
-rw-r--r-- | FrontEnd/src/app/http/bookmark.ts | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/FrontEnd/src/app/http/bookmark.ts b/FrontEnd/src/app/http/bookmark.ts new file mode 100644 index 00000000..68de4d73 --- /dev/null +++ b/FrontEnd/src/app/http/bookmark.ts @@ -0,0 +1,70 @@ +import axios from "axios"; + +import { + apiBaseUrl, + convertToNetworkError, + extractResponseData, +} from "./common"; + +import { + HttpTimelineInfo, + processRawTimelineInfo, + RawHttpTimelineInfo, +} from "./timeline"; + +export interface HttpHighlightMoveRequest { + timeline: string; + newPosition: number; +} + +export interface IHttpBookmarkClient { + list(token: string): Promise<HttpTimelineInfo[]>; + put(timeline: string, token: string): Promise<void>; + delete(timeline: string, token: string): Promise<void>; + move(req: HttpHighlightMoveRequest, token: string): Promise<void>; +} + +export class HttpHighlightClient implements IHttpBookmarkClient { + list(token: string): Promise<HttpTimelineInfo[]> { + return axios + .get<RawHttpTimelineInfo[]>(`${apiBaseUrl}/bookmarks?token=${token}`) + .then(extractResponseData) + .then((list) => list.map(processRawTimelineInfo)) + .catch(convertToNetworkError); + } + + put(timeline: string, token: string): Promise<void> { + return axios + .put(`${apiBaseUrl}/bookmarks/${timeline}?token=${token}`) + .catch(convertToNetworkError) + .then(); + } + + delete(timeline: string, token: string): Promise<void> { + return axios + .delete(`${apiBaseUrl}/bookmarks/${timeline}?token=${token}`) + .catch(convertToNetworkError) + .then(); + } + + move(req: HttpHighlightMoveRequest, token: string): Promise<void> { + return axios + .post(`${apiBaseUrl}/bookmarkop/move?token=${token}`, req) + .catch(convertToNetworkError) + .then(); + } +} + +let client: IHttpBookmarkClient = new HttpHighlightClient(); + +export function getHttpBookmarkClient(): IHttpBookmarkClient { + return client; +} + +export function setHttpBookmarkClient( + newClient: IHttpBookmarkClient +): IHttpBookmarkClient { + const old = client; + client = newClient; + return old; +} |