Dashboard with YAML
This commit is contained in:
28
server/api/folders/index.post.ts
Normal file
28
server/api/folders/index.post.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { readDb, writeDb, DashboardItem } from '../../utils/yamlDb';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
if (!body.name) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Name is required' });
|
||||
}
|
||||
|
||||
let slug = body.name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');
|
||||
if (!slug) slug = 'folder';
|
||||
|
||||
const newFolder: DashboardItem = {
|
||||
id: randomUUID(),
|
||||
type: 'folder',
|
||||
name: body.name,
|
||||
slug: slug,
|
||||
parentId: body.parentId || null,
|
||||
order: body.order || 0
|
||||
};
|
||||
|
||||
const items = readDb();
|
||||
items.push(newFolder);
|
||||
writeDb(items);
|
||||
|
||||
return newFolder;
|
||||
});
|
||||
Reference in New Issue
Block a user