main: vibe coded app to feel like paper

Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
2025-12-30 00:00:16 +03:30
parent acbaebb947
commit 91c149e92e
27 changed files with 901 additions and 8696 deletions
+22 -10
View File
@@ -1,4 +1,4 @@
import Database from 'better-sqlite3';
import { Database } from 'bun:sqlite';
import path from 'path';
import { albums as initialAlbums } from './data';
import { Album, Purchase } from './types';
@@ -7,9 +7,9 @@ import { Album, Purchase } from './types';
const dbPath = path.join(process.cwd(), 'data', 'parsa.db');
// Initialize database
let db: Database.Database;
let db: Database;
export function getDatabase(): Database.Database {
export function getDatabase(): Database {
if (!db) {
// Create data directory if it doesn't exist
const fs = require('fs');
@@ -18,8 +18,8 @@ export function getDatabase(): Database.Database {
fs.mkdirSync(dataDir, { recursive: true });
}
db = new Database(dbPath);
db.pragma('journal_mode = WAL');
db = new Database(dbPath, { create: true });
db.exec('PRAGMA journal_mode = WAL');
initializeDatabase();
}
return db;
@@ -36,6 +36,9 @@ function initializeDatabase() {
genre TEXT NOT NULL,
description TEXT NOT NULL,
price REAL NOT NULL,
tag TEXT NOT NULL DEFAULT 'Album',
format TEXT NOT NULL DEFAULT 'mp3',
bitrate TEXT NOT NULL DEFAULT '320kbps',
songs TEXT NOT NULL,
createdAt INTEGER DEFAULT (strftime('%s', 'now')),
updatedAt INTEGER DEFAULT (strftime('%s', 'now'))
@@ -73,8 +76,8 @@ function initializeDatabase() {
function seedInitialData() {
const insert = db.prepare(`
INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO albums (id, title, coverImage, year, genre, description, price, tag, format, bitrate, songs)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`);
const insertMany = db.transaction((albums: Album[]) => {
@@ -87,6 +90,9 @@ function seedInitialData() {
album.genre,
album.description,
album.price,
album.tag,
album.format,
album.bitrate,
JSON.stringify(album.songs)
);
}
@@ -119,8 +125,8 @@ export const albumDb = {
create(album: Album): void {
const db = getDatabase();
db.prepare(`
INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO albums (id, title, coverImage, year, genre, description, price, tag, format, bitrate, songs)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
album.id,
album.title,
@@ -129,6 +135,9 @@ export const albumDb = {
album.genre,
album.description,
album.price,
album.tag,
album.format,
album.bitrate,
JSON.stringify(album.songs)
);
},
@@ -137,7 +146,7 @@ export const albumDb = {
const db = getDatabase();
db.prepare(`
UPDATE albums
SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, songs = ?, updatedAt = strftime('%s', 'now')
SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, tag = ?, format = ?, bitrate = ?, songs = ?, updatedAt = strftime('%s', 'now')
WHERE id = ?
`).run(
album.title,
@@ -146,6 +155,9 @@ export const albumDb = {
album.genre,
album.description,
album.price,
album.tag,
album.format,
album.bitrate,
JSON.stringify(album.songs),
id
);