添加编辑

This commit is contained in:
2025-12-26 09:02:40 +08:00
parent 3bc3fb7d02
commit dfef53aa7a
3 changed files with 800 additions and 97 deletions

View File

@@ -1,4 +1,4 @@
import type { Project, UploadResponse, ToggleResponse } from "../types"
import type { Project, UploadResponse, ToggleResponse, ProjectDetail, UpdateProjectResponse } from "../types"
const getApiBase = () => {
if (window.location.hostname !== 'localhost') {
@@ -57,6 +57,25 @@ export const api = {
method: "PATCH",
}),
// 获取项目详情
getProjectDetail: (slug: string): Promise<ProjectDetail> =>
request<ProjectDetail>(`/projects/${slug}`),
// 更新项目
updateProject: (slug: string, formData: FormData): Promise<UpdateProjectResponse> => {
const API_BASE = getApiBase()
return fetch(`${API_BASE}/projects/${slug}`, {
method: "PUT",
body: formData,
}).then(async (response) => {
const data = await response.json()
if (!response.ok) {
throw new Error(data.error || "请求失败")
}
return data
})
},
// 删除项目
deleteProject: (slug: string): Promise<{ message: string }> =>
request<{ message: string }>(`/projects/${slug}`, {