Dashboard with YAML
This commit is contained in:
28
server/api/links/index.post.ts
Normal file
28
server/api/links/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.title || !body.url) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Title and URL are required' });
|
||||
}
|
||||
|
||||
const newLink: DashboardItem = {
|
||||
id: randomUUID(),
|
||||
type: 'link',
|
||||
parentId: body.folderId || null,
|
||||
title: body.title,
|
||||
description: body.description || undefined,
|
||||
url: body.url,
|
||||
icon: body.icon || undefined,
|
||||
color: body.color || undefined,
|
||||
order: body.order || 0
|
||||
};
|
||||
|
||||
const items = readDb();
|
||||
items.push(newLink);
|
||||
writeDb(items);
|
||||
|
||||
return newLink;
|
||||
});
|
||||
Reference in New Issue
Block a user