add /clearqueue to REST API
authorselfhoster <selfhoster@protonmail.com>
Sat, 11 Jan 2020 00:18:03 +0000 (11:18 +1100)
committerselfhoster <selfhoster@protonmail.com>
Sat, 11 Jan 2020 00:18:03 +0000 (11:18 +1100)
DeezloaderRemix.postman_collection.json
app/app.js

index db31841361d1b61bf715686613d5c278f5d18175..91c42dae8e4dfbfd4a7df6baaa6ff41a0c904815 100644 (file)
                                }
                        ],
                        "protocolProfileBehavior": {}
+               },
+               {
+                       "name": "Clear Queue",
+                       "item": [
+                               {
+                                       "name": "Clear Queue",
+                                       "request": {
+                                               "method": "GET",
+                                               "header": [
+                                                       {
+                                                               "key": "Content-Type",
+                                                               "name": "Content-Type",
+                                                               "type": "text",
+                                                               "value": "application/json"
+                                                       }
+                                               ],
+                                               "url": {
+                                                       "raw": "http://localhost:1730/api/clearqueue/",
+                                                       "protocol": "http",
+                                                       "host": [
+                                                               "localhost"
+                                                       ],
+                                                       "port": "1730",
+                                                       "path": [
+                                                               "api",
+                                                               "clearqueue",
+                                                               ""
+                                                       ]
+                                               }
+                                       },
+                                       "response": []
+                               }
+                       ],
+                       "protocolProfileBehavior": {}
                }
        ],
        "protocolProfileBehavior": {}
index 81df80a625c79e9e1e514cb927f4d337e4d6564b..567a9ead8c38ba1075177f6fe3651b3943413c7f 100644 (file)
@@ -1033,7 +1033,7 @@ io.sockets.on('connection', function (s) {
                        localDownloadQueue.splice(localDownloadQueue.indexOf(downloadQueue[queueId].id), 1);
                        delete downloadQueue[queueId]
                } else {
-                       io.sockets.emit("cancelDownload", {err: "queueID not found in downloadQueue"})
+                       io.sockets.emit("cancelDownload", {err: "queueId not found in downloadQueue"})
                }
 
                if (cancel) {
@@ -2533,13 +2533,26 @@ app.all('/api/canceldownload/', function (req, res) {
                                                res.writeHead(200, { 'Content-Type': 'application/json' });
                                        }
                                        response = `Removed ${data.queueId} from queue`
-                                       res.end(JSON.stringify({'Message': response, 'queueID': data.queueId}));
+                                       res.end(JSON.stringify({'Message': response, 'queueId': data.queueId}));
                                }
                        })
                }
        }
 });
 
+app.get('/api/clearqueue/', function (req, res) {
+       let listOfIDs = []
+       for (let i in downloadQueue) {
+               listOfIDs.push(i)
+       }
+       clientsocket.emit('cancelAllDownloads', {queueList: listOfIDs})
+
+       clientsocket.on("cancelAllDownloads", function (data) {
+               response = 'Download queue cleared'
+               res.status(200).send({"Message": response});
+       })
+});
+
 // Helper functions
 
 /**