Initial project

This commit is contained in:
Timi
2025-07-08 16:33:11 +08:00
parent 1a5a16be74
commit f862530142
80 changed files with 8301 additions and 129 deletions

36
src/api/CommentAPI.ts Normal file
View File

@@ -0,0 +1,36 @@
import {
axios,
CaptchaData,
Comment,
CommentPage,
CommentReply,
CommentReplyPage,
CommentReplyView,
CommentView,
PageResult
} from "~/index";
const BASE_URI = "/comment";
async function page(commentPage: CommentPage): Promise<PageResult<CommentView>> {
return axios.post(`${BASE_URI}/list`, commentPage);
}
async function create(captchaData: CaptchaData<Comment>): Promise<void> {
return axios.post(`${BASE_URI}/create`, captchaData);
}
async function pageReply(commentReplyPage: CommentReplyPage): Promise<PageResult<CommentReplyView>> {
return axios.post(`${BASE_URI}/reply/list`, commentReplyPage);
}
async function createReply(captchaData: CaptchaData<CommentReply>): Promise<void> {
return axios.post(`${BASE_URI}/reply/create`, captchaData);
}
export default {
page,
create,
createReply,
pageReply
};

28
src/api/CommonAPI.ts Normal file
View File

@@ -0,0 +1,28 @@
import { axios, SettingKey, TemplateBizType, Toolkit } from "~/index";
const getCaptchaAPI = () => axios.defaults.baseURL + "/captcha";
const getAttachmentReadAPI = (mongoId: string) => `${axios.defaults.baseURL}/attachment/read/${mongoId}`;
async function getTemplate(bizType: TemplateBizType, code: string): Promise<string> {
return axios.get(`/template?bizType=${bizType}&bizCode=${code}`);
}
async function getSetting(key: string, args?: { [key: string]: any }): Promise<string> {
return axios.get(`/setting/${key}?${Toolkit.toURLArgs(args)}`);
}
async function listSetting(keyMap: Map<string, object | undefined>): Promise<Map<string, string>> {
const result = await axios.post("/setting/map", Toolkit.toObject(keyMap));
const map = new Map<string, string>();
Object.entries(result).forEach(([key, value]) => map.set(key, value as string));
return map;
}
export default {
getCaptchaAPI,
getAttachmentReadAPI,
getTemplate,
getSetting,
listSetting
};

11
src/api/DeveloperAPI.ts Normal file
View File

@@ -0,0 +1,11 @@
import { axios, Developer } from "~/index";
const BASE_URI = "/git/developer";
async function get(): Promise<Developer> {
return axios.post(`${BASE_URI}`);
}
export default {
get
};

85
src/api/UserAPI.ts Normal file
View File

@@ -0,0 +1,85 @@
import {
Attachment,
axios,
CaptchaData,
CommonAPI,
LoginRequest,
LoginResponse,
RegisterRequest,
UserAttachType,
UserProfileView,
UserView
} from "~/index";
const BASE_URI = "/user";
async function register(captchaData: CaptchaData<RegisterRequest>): Promise<LoginResponse> {
return axios.post(`${BASE_URI}/register`, captchaData);
}
/**
* 登录
*
* @param captchaData 验证码登录对象
* @returns LoginResponse
*/
async function login(captchaData: CaptchaData<LoginRequest>): Promise<LoginResponse> {
return axios.post(`${BASE_URI}/login`, captchaData);
}
/**
* 验证是否已登录
*
* @returns true 为已登录
*/
async function login4Token(): Promise<LoginResponse> {
return axios.post(`${BASE_URI}/login/token`);
}
async function logout(): Promise<void> {
return axios.post(`${BASE_URI}/logout`);
}
/**
* 获取用户数据
*
* @param id 用户 ID
* @returns 用户数据
*/
async function view(id: number): Promise<UserView> {
return axios.post(`${BASE_URI}/view/${id}`);
}
function getAvatarURL(profile?: UserProfileView) {
if (profile && profile.attachmentList) {
return findAttachmentByType(profile.attachmentList, [UserAttachType.AVATAR, UserAttachType.DEFAULT_AVATAR]);
}
}
function getWrapperURL(profile?: UserProfileView) {
if (profile && profile.attachmentList) {
return findAttachmentByType(profile.attachmentList, [UserAttachType.WRAPPER, UserAttachType.DEFAULT_WRAPPER]);
}
}
function findAttachmentByType(attachmentList: Attachment[], types: UserAttachType[]) {
for (let i = 0; i < attachmentList.length; i++) {
const attachType = (<any>UserAttachType)[attachmentList[i].attachType!];
for (let type of types) {
if (attachType === type) {
return CommonAPI.getAttachmentReadAPI(attachmentList[i].mongoId);
}
}
}
}
export default {
register,
login,
login4Token,
logout,
view,
getAvatarURL,
getWrapperURL
};