aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/app/http/user.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-15 18:25:17 +0800
committerGitHub <noreply@github.com>2021-06-15 18:25:17 +0800
commit4645761c2090aeaf8c26789155b342c048f44535 (patch)
tree1aab5ce94549f3f8b3fd1a31c84fb2dd8b6b2511 /FrontEnd/src/app/http/user.ts
parent485ef185153890b7c6ac4ed9798a3f2db80c8845 (diff)
parentb6afd5e8161126522bdfff876f5483fa97e94797 (diff)
downloadtimeline-4645761c2090aeaf8c26789155b342c048f44535.tar.gz
timeline-4645761c2090aeaf8c26789155b342c048f44535.tar.bz2
timeline-4645761c2090aeaf8c26789155b342c048f44535.zip
Merge pull request #620 from crupest/vite
Migrate to vite!
Diffstat (limited to 'FrontEnd/src/app/http/user.ts')
-rw-r--r--FrontEnd/src/app/http/user.ts161
1 files changed, 0 insertions, 161 deletions
diff --git a/FrontEnd/src/app/http/user.ts b/FrontEnd/src/app/http/user.ts
deleted file mode 100644
index dcf24cba..00000000
--- a/FrontEnd/src/app/http/user.ts
+++ /dev/null
@@ -1,161 +0,0 @@
-import { AxiosError } from "axios";
-
-import {
- axios,
- apiBaseUrl,
- extractResponseData,
- convertToIfStatusCodeIs,
- convertToIfErrorCodeIs,
- extractEtag,
-} from "./common";
-
-export const kUserManagement = "UserManagement";
-export const kAllTimelineManagement = "AllTimelineManagement";
-export const kHighlightTimelineManagement = "HighlightTimelineManagement";
-
-export const kUserPermissionList = [
- kUserManagement,
- kAllTimelineManagement,
- kHighlightTimelineManagement,
-] as const;
-
-export type UserPermission = typeof kUserPermissionList[number];
-
-export interface HttpUser {
- uniqueId: string;
- username: string;
- permissions: UserPermission[];
- nickname: string;
-}
-
-export interface HttpUserPatchRequest {
- username?: string;
- password?: string;
- nickname?: string;
-}
-
-export interface HttpChangePasswordRequest {
- oldPassword: string;
- newPassword: string;
-}
-
-export interface HttpCreateUserRequest {
- username: string;
- password: string;
-}
-
-export class HttpUserNotExistError extends Error {
- constructor(public innerError?: AxiosError) {
- super();
- }
-}
-
-export class HttpChangePasswordBadCredentialError extends Error {
- constructor(public innerError?: AxiosError) {
- super();
- }
-}
-
-export interface IHttpUserClient {
- list(): Promise<HttpUser[]>;
- get(username: string): Promise<HttpUser>;
- post(req: HttpCreateUserRequest): Promise<HttpUser>;
- patch(username: string, req: HttpUserPatchRequest): Promise<HttpUser>;
- delete(username: string): Promise<void>;
- generateAvatarUrl(username: string): string;
- putAvatar(username: string, data: Blob): Promise<string>;
- changePassword(req: HttpChangePasswordRequest): Promise<void>;
- putUserPermission(
- username: string,
- permission: UserPermission
- ): Promise<void>;
- deleteUserPermission(
- username: string,
- permission: UserPermission
- ): Promise<void>;
-}
-
-export class HttpUserClient implements IHttpUserClient {
- list(): Promise<HttpUser[]> {
- return axios
- .get<HttpUser[]>(`${apiBaseUrl}/users`)
- .then(extractResponseData);
- }
-
- get(username: string): Promise<HttpUser> {
- return axios
- .get<HttpUser>(`${apiBaseUrl}/users/${username}`)
- .then(extractResponseData)
- .catch(convertToIfStatusCodeIs(404, HttpUserNotExistError));
- }
-
- post(req: HttpCreateUserRequest): Promise<HttpUser> {
- return axios
- .post<HttpUser>(`${apiBaseUrl}/users`, req)
- .then(extractResponseData)
- .then();
- }
-
- patch(username: string, req: HttpUserPatchRequest): Promise<HttpUser> {
- return axios
- .patch<HttpUser>(`${apiBaseUrl}/users/${username}`, req)
- .then(extractResponseData);
- }
-
- delete(username: string): Promise<void> {
- return axios.delete(`${apiBaseUrl}/users/${username}`).then();
- }
-
- generateAvatarUrl(username: string): string {
- return `${apiBaseUrl}/users/${username}/avatar`;
- }
-
- putAvatar(username: string, data: Blob): Promise<string> {
- return axios
- .put(`${apiBaseUrl}/users/${username}/avatar`, data, {
- headers: {
- "Content-Type": data.type,
- },
- })
- .then(extractEtag);
- }
-
- changePassword(req: HttpChangePasswordRequest): Promise<void> {
- return axios
- .post(`${apiBaseUrl}/userop/changepassword`, req)
- .catch(
- convertToIfErrorCodeIs(11020201, HttpChangePasswordBadCredentialError)
- )
- .then();
- }
-
- putUserPermission(
- username: string,
- permission: UserPermission
- ): Promise<void> {
- return axios
- .put(`${apiBaseUrl}/users/${username}/permissions/${permission}`)
- .then();
- }
-
- deleteUserPermission(
- username: string,
- permission: UserPermission
- ): Promise<void> {
- return axios
- .delete(`${apiBaseUrl}/users/${username}/permissions/${permission}`)
- .then();
- }
-}
-
-let client: IHttpUserClient = new HttpUserClient();
-
-export function getHttpUserClient(): IHttpUserClient {
- return client;
-}
-
-export function setHttpUserClient(newClient: IHttpUserClient): IHttpUserClient {
- const old = client;
- client = newClient;
- return old;
-}