v0.0.23
This commit is contained in:
+9
-5
@@ -1,8 +1,12 @@
|
||||
import {Attachment, CaptchaData, LoginRequest, LoginResponse, RegisterRequest, UpdatePasswordRequest, User, UserAttachType} from "../types";
|
||||
import type {Attachment, CaptchaData, LoginRequest, LoginResponse, RegisterRequest, UpdatePasswordRequest, User} from "../types";
|
||||
import {UserAttachType} from "../types";
|
||||
import {axios} from "./BaseAPI";
|
||||
import CommonAPI from "./CommonAPI";
|
||||
|
||||
const BASE_URI = "/user";
|
||||
type UserAttachmentOwner = {
|
||||
attachmentList?: readonly Attachment[];
|
||||
};
|
||||
|
||||
async function register(req: CaptchaData<RegisterRequest>): Promise<LoginResponse> {
|
||||
return await axios.post(`${BASE_URI}/register`, req);
|
||||
@@ -31,7 +35,7 @@ async function logout(): Promise<void> {
|
||||
return await axios.post(`${BASE_URI}/logout`);
|
||||
}
|
||||
|
||||
async function updateCurrent(req: User): Promise<LoginResponse> {
|
||||
async function updateCurrent(req: Partial<User>): Promise<LoginResponse> {
|
||||
return await axios.post(`${BASE_URI}/current/update`, req);
|
||||
}
|
||||
|
||||
@@ -49,19 +53,19 @@ async function view(id: string): Promise<User> {
|
||||
return await axios.post(`${BASE_URI}/view/${id}`);
|
||||
}
|
||||
|
||||
function getAvatarURL(user?: User) {
|
||||
function getAvatarURL(user?: UserAttachmentOwner) {
|
||||
if (user?.attachmentList) {
|
||||
return findAttachmentByType(user.attachmentList, [UserAttachType.AVATAR, UserAttachType.DEFAULT_AVATAR]);
|
||||
}
|
||||
}
|
||||
|
||||
function getWrapperURL(user?: User) {
|
||||
function getWrapperURL(user?: UserAttachmentOwner) {
|
||||
if (user?.attachmentList) {
|
||||
return findAttachmentByType(user.attachmentList, [UserAttachType.WRAPPER, UserAttachType.DEFAULT_WRAPPER]);
|
||||
}
|
||||
}
|
||||
|
||||
function findAttachmentByType(attachmentList: Attachment[], types: UserAttachType[]) {
|
||||
function findAttachmentByType(attachmentList: readonly Attachment[], types: UserAttachType[]) {
|
||||
for (let i = 0; i < attachmentList.length; i++) {
|
||||
const attachType = attachmentList[i].attachType as UserAttachType | undefined;
|
||||
const id = attachmentList[i].id;
|
||||
|
||||
Reference in New Issue
Block a user