模型库初版提交

This commit is contained in:
zhangshun
2026-05-25 08:49:29 +08:00
parent 5d08480921
commit c2ac560527
7 changed files with 17 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ const updateSchema = z.object({
function buildTree(rows: FolderRow[]) {
const nodes = rows.map((row) => ({
id: String(row.id),
text: row.name,
text: `${row.name}(${row.model_count ?? 0})`,
parentId: row.parent_id,
path: row.path,
children: [] as unknown[]
@@ -53,7 +53,15 @@ function assertCanRenameRoot(folder: FolderRow) {
export async function folderRoutes(app: FastifyInstance) {
app.get("/api/folders", { preHandler: [requireAuth] }, async () => {
const rows = db.prepare("SELECT * FROM folders ORDER BY parent_id, name").all() as unknown as FolderRow[];
const rows = db.prepare(`
SELECT
f.*,
COUNT(m.id) AS model_count
FROM folders f
LEFT JOIN models m ON m.folder_id = f.id
GROUP BY f.id
ORDER BY f.parent_id, f.name
`).all() as unknown as FolderRow[];
return { folders: rows, tree: buildTree(rows) };
});

View File

@@ -22,6 +22,7 @@ export interface FolderRow {
parent_id: number | null;
name: string;
path: string;
model_count?: number;
created_at: string;
updated_at: string;
}