Implemented removeFromQueue and cancelAllDownloads
This commit is contained in:
parent
de85a39718
commit
fa6826c554
@ -15,7 +15,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cookie-parser": "1.4.5",
|
"cookie-parser": "1.4.5",
|
||||||
"debug": "2.6.9",
|
"debug": "2.6.9",
|
||||||
"deemix": "0.0.3",
|
"deemix": "0.0.4",
|
||||||
"deezer-js": "0.0.10",
|
"deezer-js": "0.0.10",
|
||||||
"dotenv": "8.2.0",
|
"dotenv": "8.2.0",
|
||||||
"express": "4.17.1",
|
"express": "4.17.1",
|
||||||
|
@ -84,6 +84,8 @@ async function startQueue(dz: any): Promise<any> {
|
|||||||
currentJob = true // lock currentJob
|
currentJob = true // lock currentJob
|
||||||
|
|
||||||
const currentUUID: string = queueOrder.shift() || ""
|
const currentUUID: string = queueOrder.shift() || ""
|
||||||
|
console.log(currentUUID)
|
||||||
|
queue[currentUUID].status = "downloading"
|
||||||
const currentItem: any = JSON.parse(fs.readFileSync(configFolder + `queue${sep}${currentUUID}.json`).toString())
|
const currentItem: any = JSON.parse(fs.readFileSync(configFolder + `queue${sep}${currentUUID}.json`).toString())
|
||||||
let downloadObject: any
|
let downloadObject: any
|
||||||
switch (currentItem.__type__) {
|
switch (currentItem.__type__) {
|
||||||
@ -100,9 +102,9 @@ async function startQueue(dz: any): Promise<any> {
|
|||||||
}
|
}
|
||||||
currentJob = new Downloader(dz, downloadObject, settings, listener)
|
currentJob = new Downloader(dz, downloadObject, settings, listener)
|
||||||
listener.send('startDownload', currentUUID)
|
listener.send('startDownload', currentUUID)
|
||||||
queue[currentUUID].status = "downloading"
|
|
||||||
await currentJob.start()
|
await currentJob.start()
|
||||||
|
|
||||||
|
if (! downloadObject.isCanceled){
|
||||||
// Set status
|
// Set status
|
||||||
if (downloadObject.failed == downloadObject.size){
|
if (downloadObject.failed == downloadObject.size){
|
||||||
queue[currentUUID].status = "failed"
|
queue[currentUUID].status = "failed"
|
||||||
@ -117,12 +119,49 @@ async function startQueue(dz: any): Promise<any> {
|
|||||||
|
|
||||||
// Save queue status
|
// Save queue status
|
||||||
fs.writeFileSync(configFolder + `queue${sep}${currentUUID}.json`, JSON.stringify(savedObject))
|
fs.writeFileSync(configFolder + `queue${sep}${currentUUID}.json`, JSON.stringify(savedObject))
|
||||||
|
}
|
||||||
|
console.log(queueOrder)
|
||||||
fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder))
|
fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder))
|
||||||
|
|
||||||
currentJob = null
|
currentJob = null
|
||||||
} while (queueOrder.length)
|
} while (queueOrder.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cancelDownload(uuid: string){
|
||||||
|
if (Object.keys(queue).includes(uuid)){
|
||||||
|
switch (queue[uuid].status) {
|
||||||
|
case "downloading":
|
||||||
|
currentJob.downloadObject.isCanceled = true
|
||||||
|
listener.send("cancellingCurrentItem", uuid)
|
||||||
|
break
|
||||||
|
case "inQueue":
|
||||||
|
queueOrder.splice(queueOrder.indexOf(uuid), 1)
|
||||||
|
fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder))
|
||||||
|
default:
|
||||||
|
listener.send("removedFromQueue", uuid)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fs.unlinkSync(configFolder + `queue${sep}${uuid}.json`)
|
||||||
|
delete queue[uuid]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cancelAllDownloads(){
|
||||||
|
queueOrder = []
|
||||||
|
let currentItem: string | null = null
|
||||||
|
Object.values(queue).forEach((downloadObject: any) => {
|
||||||
|
if (downloadObject.status == "downloading"){
|
||||||
|
currentJob.downloadObject.isCanceled = true
|
||||||
|
listener.send("cancellingCurrentItem", downloadObject.uuid)
|
||||||
|
currentItem = downloadObject.uuid
|
||||||
|
}
|
||||||
|
fs.unlinkSync(configFolder + `queue${sep}${downloadObject.uuid}.json`)
|
||||||
|
delete queue[downloadObject.uuid]
|
||||||
|
})
|
||||||
|
fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder))
|
||||||
|
listener.send("removedAllDownloads", currentItem)
|
||||||
|
}
|
||||||
|
|
||||||
export function clearCompletedDownloads(){
|
export function clearCompletedDownloads(){
|
||||||
Object.values(queue).forEach((downloadObject: any) => {
|
Object.values(queue).forEach((downloadObject: any) => {
|
||||||
if (downloadObject.status === "completed"){
|
if (downloadObject.status === "completed"){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
import { Deezer } from 'deezer-js'
|
import { Deezer } from 'deezer-js'
|
||||||
import { sessionDZ } from '../main'
|
import { sessionDZ, queue, queueOrder, currentJob } from '../main'
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ router.get('/connect', (req, res) => {
|
|||||||
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
|
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
|
||||||
const dz = sessionDZ[req.session.id]
|
const dz = sessionDZ[req.session.id]
|
||||||
|
|
||||||
res.send({
|
let result: any = {
|
||||||
update: {
|
update: {
|
||||||
currentCommit: 'testing',
|
currentCommit: 'testing',
|
||||||
latestCommit: 'testing',
|
latestCommit: 'testing',
|
||||||
@ -28,7 +28,19 @@ router.get('/connect', (req, res) => {
|
|||||||
autologin: !dz.logged_in,
|
autologin: !dz.logged_in,
|
||||||
currentUser: dz.current_user,
|
currentUser: dz.current_user,
|
||||||
deezerNotAvailable: false
|
deezerNotAvailable: false
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (Object.keys(queue).length > 0){
|
||||||
|
result.queue = {
|
||||||
|
queue,
|
||||||
|
queueOrder
|
||||||
|
}
|
||||||
|
if (currentJob && currentJob !== true){
|
||||||
|
result.queue.current = currentJob.downloadObject.uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.send(result)
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
import { Server as WsServer } from 'ws'
|
||||||
|
import { consoleInfo } from '../../helpers/errors'
|
||||||
|
import { cancelAllDownloads } from '../../main'
|
||||||
|
|
||||||
|
const eventName = 'cancelAllDownloads'
|
||||||
|
|
||||||
|
const cb = (_: any, __: any, ___: WsServer) => {
|
||||||
|
cancelAllDownloads()
|
||||||
|
consoleInfo(`Queue cleared`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { eventName, cb }
|
@ -1,7 +1,11 @@
|
|||||||
import saveSettings from './saveSettings'
|
import saveSettings from './saveSettings'
|
||||||
import removeFinishedDownloads from './removeFinishedDownloads'
|
import removeFinishedDownloads from './removeFinishedDownloads'
|
||||||
|
import removeFromQueue from './removeFromQueue'
|
||||||
|
import cancelAllDownloads from './cancelAllDownloads'
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
saveSettings,
|
saveSettings,
|
||||||
removeFinishedDownloads
|
removeFinishedDownloads,
|
||||||
|
removeFromQueue,
|
||||||
|
cancelAllDownloads
|
||||||
]
|
]
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
import { Server as WsServer } from 'ws'
|
||||||
|
import { consoleInfo } from '../../helpers/errors'
|
||||||
|
import { cancelDownload } from '../../main'
|
||||||
|
|
||||||
|
const eventName = 'removeFromQueue'
|
||||||
|
|
||||||
|
const cb = (data: any, __: any, ___: WsServer) => {
|
||||||
|
cancelDownload(data)
|
||||||
|
consoleInfo(`Cancelled ${data}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { eventName, cb }
|
@ -1878,10 +1878,10 @@ decompress-response@^6.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
mimic-response "^3.1.0"
|
mimic-response "^3.1.0"
|
||||||
|
|
||||||
deemix@0.0.3:
|
deemix@0.0.4:
|
||||||
version "0.0.3"
|
version "0.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.0.3.tgz#a32b1b3c8e99fe26ea7a326658e49b4892c96dd5"
|
resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.0.4.tgz#20077d643d6b87675b95d647315164a5852176a2"
|
||||||
integrity sha512-cUsfliHRXWLOYB7K+UCN0Lmx3d4ueWfaQ/Xinhg8/cHetifJC4/CxD8YDdBArI7Fl3StkJVGt45BajU/z00k6Q==
|
integrity sha512-d4WfVhfgiH5Zjxs6tNWyrMRd/ea7wLc3zlyP5TAVmK6HuAjvicLPNCjFxCMOrufuZVPRxjv4EtKiMpB7U+xDdQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
async "^3.2.0"
|
async "^3.2.0"
|
||||||
browser-id3-writer "^4.4.0"
|
browser-id3-writer "^4.4.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user