模型库初版提交
This commit is contained in:
@@ -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) };
|
||||
});
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ export interface FolderRow {
|
||||
parent_id: number | null;
|
||||
name: string;
|
||||
path: string;
|
||||
model_count?: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user