feat: rename graph titles with select-then-edit interaction
This commit is contained in:
@@ -8,6 +8,7 @@ export type Board = {
|
||||
title: string;
|
||||
version: number;
|
||||
content?: { schema_version: number };
|
||||
description?: string;
|
||||
};
|
||||
export const DEFAULT_BOARD_TITLE = "未命名图谱";
|
||||
|
||||
@@ -56,3 +57,18 @@ export async function createBoard(
|
||||
});
|
||||
return { ...result, workspace_id: result.workspace_id || id, title: name };
|
||||
}
|
||||
|
||||
|
||||
export async function renameBoard(request: Request, workspaceId: string, boardId: string, title: string): Promise<Board> {
|
||||
const name = title.trim();
|
||||
if (!name || new TextEncoder().encode(name).length > 300) throw new Error("invalid_title");
|
||||
const path = `workspaces/${encodeURIComponent(workspaceId)}/materials/${encodeURIComponent(boardId)}`;
|
||||
const current = await request<Board>(path);
|
||||
if (current.kind !== "board" || current.id !== boardId || current.workspace_id !== workspaceId) throw new Error("invalid_reference");
|
||||
await request(path, {
|
||||
method: "PATCH",
|
||||
headers: { "If-Match": `"${current.version}"` },
|
||||
body: JSON.stringify({ title: name, description: current.description || "", content: current.content || { schema_version: 1 } }),
|
||||
});
|
||||
return { ...current, title: name, version: current.version + 1 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user