feat: restructure client-side code
This commit is contained in:
18
src/server/game/deck.js
Normal file
18
src/server/game/deck.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { parseFile as mmParseFile } from 'music-metadata';
|
||||
import { DATA_DIR } from '../config.js';
|
||||
import { loadYearsIndex } from '../years.js';
|
||||
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 };
|
||||
}));
|
||||
return shuffle(tracks);
|
||||
}
|
||||
Reference in New Issue
Block a user