/api/queue, returns length and items of downloadQueue
authorselfhoster <selfhoster@protonmail.com>
Sat, 30 Nov 2019 00:34:22 +0000 (11:34 +1100)
committerselfhoster <selfhoster@protonmail.com>
Sat, 30 Nov 2019 00:34:22 +0000 (11:34 +1100)
app/app.js

index 87474522b7902c18a489af8d3eecdbe745fe94c1..ed2404abc52083ee0b7e3aa3fa3a9ce27825f06d 100644 (file)
@@ -174,6 +174,18 @@ app.post('/api/tracks/', function (req, res) {
                })
        }
 });
+
+app.get('/api/queue/', function (req, res) {
+       //accepts nothing, returns length of, and items in download queue
+       let itemsInQueue = Object.keys(downloadQueue).length
+       let queueItems = []
+       for (let item in downloadQueue) {
+               queueItems.push(downloadQueue[item])
+       }
+       res.writeHead(200, { 'Content-Type': 'application/json' });
+       res.end(JSON.stringify({"length": itemsInQueue, "items": queueItems}));
+});
+
 var dqueue = new stq.SequentialTaskQueue()
 var downloadQueue = {}
 var trackQueue = queue({