Initial commit: Admin panel

This commit is contained in:
Noro Studio
2026-06-30 00:50:13 +03:30
commit 79491cd8ef
36 changed files with 6448 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const DATA_DIR = join(__dirname, '..', 'data')
const DB_PATH = join(DATA_DIR, 'content.json')
const defaultDb = () => ({
site: {},
navigation: [],
portfolioCategories: [],
projects: [],
services: [],
serviceProjectCategories: {},
clients: [],
stats: [],
blogPosts: [],
media: []
})
function ensureDataDir() {
if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true })
}
export function readDb() {
ensureDataDir()
if (!existsSync(DB_PATH)) {
const db = defaultDb()
writeDb(db)
return db
}
return JSON.parse(readFileSync(DB_PATH, 'utf-8'))
}
export function writeDb(db) {
ensureDataDir()
writeFileSync(DB_PATH, JSON.stringify(db, null, 2), 'utf-8')
}
export function updateDb(mutator) {
const db = readDb()
mutator(db)
writeDb(db)
return db
}