This commit is contained in:
Timi
2026-07-31 15:28:13 +08:00
parent fc816e2d84
commit 2cf33d1003
8 changed files with 106 additions and 16 deletions
+9 -5
View File
@@ -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;