mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 19:49:31 -07:00
playlist json
This commit is contained in:
@@ -3,6 +3,7 @@ import fs from 'fs';
|
|||||||
import corsPassThru from './cors/index.mjs';
|
import corsPassThru from './cors/index.mjs';
|
||||||
import radarPassThru from './cors/radar.mjs';
|
import radarPassThru from './cors/radar.mjs';
|
||||||
import outlookPassThru from './cors/outlook.mjs';
|
import outlookPassThru from './cors/outlook.mjs';
|
||||||
|
import playlist from './src/playlist.mjs';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.WS4KP_PORT ?? 8080;
|
const port = process.env.WS4KP_PORT ?? 8080;
|
||||||
@@ -14,6 +15,7 @@ app.set('view engine', 'ejs');
|
|||||||
app.get('/stations/*', corsPassThru);
|
app.get('/stations/*', corsPassThru);
|
||||||
app.get('/Conus/*', radarPassThru);
|
app.get('/Conus/*', radarPassThru);
|
||||||
app.get('/products/*', outlookPassThru);
|
app.get('/products/*', outlookPassThru);
|
||||||
|
app.get('/playlist.json', playlist);
|
||||||
|
|
||||||
// version
|
// version
|
||||||
const { version } = JSON.parse(fs.readFileSync('package.json'));
|
const { version } = JSON.parse(fs.readFileSync('package.json'));
|
||||||
|
|||||||
12
src/playlist-reader.mjs
Normal file
12
src/playlist-reader.mjs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
|
const reader = async () => {
|
||||||
|
// get the listing of files in the folder
|
||||||
|
const rawFiles = await fs.readdir('./server/music');
|
||||||
|
// filter for mp3 files
|
||||||
|
const files = rawFiles.filter((file) => file.match(/\.mp3$/));
|
||||||
|
console.log(files);
|
||||||
|
return files;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default reader;
|
||||||
15
src/playlist.mjs
Normal file
15
src/playlist.mjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import reader from './playlist-reader.mjs';
|
||||||
|
|
||||||
|
const playlistGenerator = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const availableFiles = await reader();
|
||||||
|
res.json({
|
||||||
|
availableFiles,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
res.send();
|
||||||
|
};
|
||||||
|
|
||||||
|
export default playlistGenerator;
|
||||||
Reference in New Issue
Block a user