2025-03-22 13:52:00 +01:00
|
|
|
import fs from 'fs/promises';
|
|
|
|
|
|
2025-03-24 18:24:49 -05:00
|
|
|
const mp3Filter = (file) => file.match(/\.mp3$/);
|
|
|
|
|
|
2025-03-22 13:52:00 +01:00
|
|
|
const reader = async () => {
|
|
|
|
|
// get the listing of files in the folder
|
|
|
|
|
const rawFiles = await fs.readdir('./server/music');
|
|
|
|
|
// filter for mp3 files
|
2025-03-24 18:24:49 -05:00
|
|
|
const files = rawFiles.filter(mp3Filter);
|
|
|
|
|
// if files were found return them
|
|
|
|
|
if (files.length > 0) {
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fall back to the default folder
|
|
|
|
|
const defaultFiles = await fs.readdir('./server/music/default');
|
|
|
|
|
return defaultFiles.map(file => `default/${file}`).filter(mp3Filter);
|
|
|
|
|
|
2025-03-22 13:52:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default reader;
|