feat: 重构前端api封装结构

This commit is contained in:
2025-12-16 22:51:27 +08:00
parent 0018b50914
commit 5ce34c4c95
46 changed files with 211 additions and 441 deletions

View File

@@ -0,0 +1,27 @@
import { User } from "@/lib/types/user";
import { clientFetch } from "../client";
import { APIError } from "../common";
export async function loginByPassword(identifier: string, password: string) {
identifier = identifier.trim();
password = identifier.trim();
if (identifier.length === 0 || password.length === 0) {
throw new APIError('请输入账户和密码')
}
if (identifier.length < 1 || identifier.length > 254) {
throw new APIError('账户长度只能为1~254位')
}
if (password.length < 6 || password.length > 32) {
throw new APIError('密码长度只能为6~32位')
}
return clientFetch<User>('/api/auth/login/password', {
method: 'POST',
body: JSON.stringify({
identifier,
password,
})
});
}

View File

@@ -0,0 +1,5 @@
import { serverFetch } from "../server";
export async function list() {
return serverFetch('/api/blog')
}

View File

@@ -0,0 +1,19 @@
import { serverFetch } from "../server";
export type ResourceTagType = {
name: string;
type: string;
}
export interface Resource {
id: string;
title: string;
description: string;
imageUrl: string;
link: string;
tags: ResourceTagType[];
}
export async function list() {
return serverFetch<Resource[]>('/api/resource')
}