diff --git a/routes/index.js b/routes/index.js index c1b35db..c3760b6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -11,6 +11,7 @@ var router = express.Router(); router.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + res.header('Cache-Control', 'no-cache'); next(); }); const rootdir = path.join(__dirname, '/../'); @@ -45,15 +46,22 @@ router.get('/download/:url', (req, res, _next) => { }); }); +router.get('/info/:id', (req, res, _next) => { + ytdl.getBasicInfo(req.params.id, (_err, info) => { + res.json({ result: info }); + }) +}); + router.get('/downloadqueue', (req, res, _next) => { res.json({ result: downloadQueue }); }) function dbGet(type, id) { + JSON.parse(fs.readFileSync(rootdir + "database/albums.json").toString()); let db = { - song: require(rootdir + 'database/songs.json'), - album: require(rootdir + "database/albums.json"), - artist: require(rootdir + "database/artists.json") + song: JSON.parse(fs.readFileSync(rootdir + "database/songs.json").toString()), + album: JSON.parse(fs.readFileSync(rootdir + "database/albums.json").toString()), + artist: JSON.parse(fs.readFileSync(rootdir + "database/artists.json").toString()) }; let result; @@ -198,4 +206,22 @@ router.get('/duration/:file', (req, res, _next) => { getAudioDurationInSeconds(__dirname + '/../music/' + req.params.file).then(duration => res.json({result: duration})); }) +router.get('/update/:database/:index/:field/:value', (req, res, _next) => { + const path = rootdir + "database/" + req.params.database + ".json"; + const db = require(path); + db[req.params.index][req.params.field] = req.params.value; + fs.writeFileSync(path, JSON.stringify(db)); + + res.json({ result: true }); +}); + +router.get('/insert/:database/', (req, res, _next) => { + const path = rootdir + "database/" + req.params.database + ".json"; + const db = JSON.parse(fs.readFileSync(path).toString()); + const index = db.push({}) - 1; + db[index].id = index; + fs.writeFileSync(path, JSON.stringify(db)); + res.json({ result: db[index] }); +}); + module.exports = router;