Refactor code structure for improved readability and maintainability
All checks were successful
Build and Push Docker Image / docker (push) Successful in 21s

This commit is contained in:
2025-09-04 21:53:54 +02:00
parent 80f8c4ca90
commit 8c5ca0044f
27 changed files with 3398 additions and 326 deletions

View File

@@ -8,11 +8,21 @@ import { shuffle } from './state.js';
export async function loadDeck() {
const years = loadYearsIndex();
const files = fs.readdirSync(DATA_DIR).filter((f) => /\.(mp3|wav|m4a|ogg)$/i.test(f));
const tracks = await Promise.all(files.map(async (f) => {
const fp = path.join(DATA_DIR, f);
let year = null, title = path.parse(f).name, artist = '';
try { const meta = await mmParseFile(fp, { duration: false }); title = meta.common.title || title; artist = meta.common.artist || artist; year = meta.common.year || null; } catch {}
const y = years[f]?.year ?? year; return { id: f, file: f, title, artist, year: y };
}));
const tracks = await Promise.all(
files.map(async (f) => {
const fp = path.join(DATA_DIR, f);
let year = null,
title = path.parse(f).name,
artist = '';
try {
const meta = await mmParseFile(fp, { duration: false });
title = meta.common.title || title;
artist = meta.common.artist || artist;
year = meta.common.year || null;
} catch {}
const y = years[f]?.year ?? year;
return { id: f, file: f, title, artist, year: y };
})
);
return shuffle(tracks);
}