Dashboard with YAML
This commit is contained in:
32
server/utils/yamlDb.ts
Normal file
32
server/utils/yamlDb.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
const dbPath = path.resolve(process.cwd(), 'app/dashboard.yml');
|
||||
|
||||
export interface DashboardItem {
|
||||
id: string;
|
||||
type: 'folder' | 'link';
|
||||
parentId: string | null;
|
||||
name?: string;
|
||||
slug?: string;
|
||||
title?: string;
|
||||
url?: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
color?: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export function readDb(): DashboardItem[] {
|
||||
if (!fs.existsSync(dbPath)) {
|
||||
return [];
|
||||
}
|
||||
const fileContents = fs.readFileSync(dbPath, 'utf8');
|
||||
return (yaml.load(fileContents) as DashboardItem[]) || [];
|
||||
}
|
||||
|
||||
export function writeDb(data: DashboardItem[]) {
|
||||
const yamlStr = yaml.dump(data);
|
||||
fs.writeFileSync(dbPath, yamlStr, 'utf8');
|
||||
}
|
||||
Reference in New Issue
Block a user