Refactor code structure for improved readability and maintainability
All checks were successful
Build and Push Docker Image / docker (push) Successful in 21s
All checks were successful
Build and Push Docker Image / docker (push) Successful in 21s
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user