From 841b501c301a3df800c23445aedf772d3d79dc64 Mon Sep 17 00:00:00 2001 From: Audit Bot Date: Sun, 28 Jun 2026 22:01:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=B4=A0=E6=9D=90=E5=BA=93=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96/=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=BB=98=E8=AE=A4=E9=A1=B9=E7=9B=AE=E4=BB=A5=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=20project=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 api/projects.ts:项目 API 模块,含 getOrCreateDefaultProject - 修改 createAssetLibrary:自动解析 project_id 再发送请求 - 后端 CreateAssetLibraryRequest 要求 project_id,前端之前未发送导致 422 - 修复 P0:新建素材库点击确定无响应 Co-Authored-By: Claude Fable 5 --- apps/web/src/api/assets.ts | 10 ++++-- apps/web/src/api/projects.ts | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 apps/web/src/api/projects.ts diff --git a/apps/web/src/api/assets.ts b/apps/web/src/api/assets.ts index 56a20468d..b95c736fb 100644 --- a/apps/web/src/api/assets.ts +++ b/apps/web/src/api/assets.ts @@ -3,6 +3,7 @@ * Phase 1 重构:去掉 project_id,素材直接归属用户 */ import apiClient from './client'; +import { getOrCreateDefaultProject } from './projects'; /** 素材条目 */ export interface AssetItem { @@ -93,12 +94,17 @@ export const getAssetLibraries = async (): Promise => { return response.data.items || []; }; -/** 创建素材库 */ +/** 创建素材库(自动获取或创建默认项目以提供 project_id) */ export const createAssetLibrary = async (data: { name: string; kind: 'video' | 'voice' | 'image'; }): Promise => { - const response = await apiClient.post('/asset-libraries', data); + // 后端要求 project_id,前端自动管理默认项目 + const project = await getOrCreateDefaultProject(); + const response = await apiClient.post('/asset-libraries', { + project_id: project.id, + ...data, + }); return response.data; }; diff --git a/apps/web/src/api/projects.ts b/apps/web/src/api/projects.ts new file mode 100644 index 000000000..4367ae395 --- /dev/null +++ b/apps/web/src/api/projects.ts @@ -0,0 +1,60 @@ +/** + * 项目相关 API + * 素材库需要 project_id,前端自动管理默认项目 + */ +import apiClient from './client'; + +export interface ProjectItem { + id: string; + owner_user_id: string; + name: string; + description: string; + shared_users: string[]; +} + +interface BackendProjectResponse { + id: string; + owner_user_id: string; + name: string; + description: string; + shared_users: string[]; +} + +const toProjectItem = (item: BackendProjectResponse): ProjectItem => ({ + id: item.id, + owner_user_id: item.owner_user_id, + name: item.name, + description: item.description, + shared_users: item.shared_users || [], +}); + +/** 获取当前用户的项目列表 */ +export const getProjects = async (): Promise => { + const response = await apiClient.get('/projects'); + return (response.data || []).map(toProjectItem); +}; + +/** 创建项目 */ +export const createProject = async (data: { + name: string; + description?: string; +}): Promise => { + const response = await apiClient.post('/projects', { + name: data.name, + description: data.description || '', + }); + return toProjectItem(response.data); +}; + +/** 获取或创建默认项目(素材库需要 project_id) */ +export const getOrCreateDefaultProject = async (): Promise => { + const projects = await getProjects(); + if (projects.length > 0) { + return projects[0]; + } + // 没有项目时自动创建默认项目 + return createProject({ + name: '默认项目', + description: '系统自动创建的默认项目', + }); +}; -- 2.54.0 From 5eacac3abfdb7a13398c7c001985feb7314f9bc4 Mon Sep 17 00:00:00 2001 From: Audit Bot Date: Mon, 29 Jun 2026 07:25:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20getProjects=20?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E8=A7=A3=E6=9E=90=20=E2=80=94=20=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E8=BF=94=E5=9B=9E=20{items:[...]}=20=E8=80=8C?= =?UTF-8?q?=E9=9D=9E=E8=A3=B8=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BackendProjectResponse 对齐后端 ProjectResponse(仅 id/name/description) - getProjects 改为 response.data.items 解析 - 修复代码审计 PR#94 审查发现的 P0 Co-Authored-By: Claude Fable 5 --- apps/web/src/api/projects.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/web/src/api/projects.ts b/apps/web/src/api/projects.ts index 4367ae395..fb3d73bb1 100644 --- a/apps/web/src/api/projects.ts +++ b/apps/web/src/api/projects.ts @@ -6,32 +6,32 @@ import apiClient from './client'; export interface ProjectItem { id: string; - owner_user_id: string; name: string; description: string; - shared_users: string[]; } +/** 后端 ProjectResponse 只返回 id, name, description */ interface BackendProjectResponse { id: string; - owner_user_id: string; name: string; description: string; - shared_users: string[]; +} + +/** 后端 ListProjectsResponse 返回 { items: [...] } */ +interface BackendListProjectsResponse { + items: BackendProjectResponse[]; } const toProjectItem = (item: BackendProjectResponse): ProjectItem => ({ id: item.id, - owner_user_id: item.owner_user_id, name: item.name, description: item.description, - shared_users: item.shared_users || [], }); /** 获取当前用户的项目列表 */ export const getProjects = async (): Promise => { - const response = await apiClient.get('/projects'); - return (response.data || []).map(toProjectItem); + const response = await apiClient.get('/projects'); + return (response.data.items || []).map(toProjectItem); }; /** 创建项目 */ -- 2.54.0