Added retry function

This commit is contained in:
RemixDev 2022-08-19 23:50:05 +02:00
parent 12d6cafdd0
commit 06305de9cf
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
4 changed files with 62 additions and 4 deletions

View File

@ -158,7 +158,7 @@ export class DeemixApp {
return result
}
async addToQueue(dz: any, url: string[], bitrate: number) {
async addToQueue(dz: any, url: string[], bitrate: number, retry: boolean = false) {
if (!dz.logged_in) throw new NotLoggedIn()
if (
!this.settings.feelingLucky &&
@ -204,7 +204,7 @@ export class DeemixApp {
downloadObjs.forEach((downloadObj: any) => {
// Check if element is already in queue
if (Object.keys(this.queue).includes(downloadObj.uuid)) {
if (Object.keys(this.queue).includes(downloadObj.uuid) && !retry) {
this.listener.send('alreadyInQueue', downloadObj.getEssentialDict())
return
}

View File

@ -7,6 +7,7 @@ import removeFinishedDownloads from './removeFinishedDownloads'
import removeFromQueue from './removeFromQueue'
import logout from './logout'
import saveSettings from './saveSettings'
import retryDownload from './retryDownload'
export default [
changeAccount,
@ -17,5 +18,6 @@ export default [
removeFinishedDownloads,
removeFromQueue,
logout,
saveSettings
saveSettings,
retryDownload
]

View File

@ -0,0 +1,56 @@
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../app'
import { logger } from '../../../helpers/logger'
const path: ApiHandler['path'] = '/retryDownload'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const deemix = req.app.get('deemix')
const dz = sessionDZ[req.session.id]
const uuid = req.body.uuid
const data = uuid.split('_')
let url = ''
let bitrate = 0
if (data.lenght === 4) {
if (data[0] === 'spotify') {
url = `https://open.spotify.com/${data[1]}/${data[2]}`
bitrate = Number(data[3])
}
} else {
if (data[0] === 'playlist' && data[1].endsWith('_top_track')) {
data[0] = 'artist'
data[1] = data[1].replace('_top_track', '/top_track')
}
url = `https://www.deezer.com/${data[0]}/${data[1]}`
bitrate = Number(data[2])
}
let obj: any
try {
obj = await deemix.addToQueue(dz, [url], bitrate, true)
} catch (e) {
res.send({ result: false, errid: e.name, data: { url, bitrate } })
switch (e.name) {
case 'NotLoggedIn':
deemix.listener.send('queueError' + e.name)
break
case 'CantStream':
deemix.listener.send('queueError' + e.name, e.bitrate)
break
default:
logger.error(e)
break
}
return
}
res.send({ result: true, data: { url, bitrate, obj } })
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

2
webui

@ -1 +1 @@
Subproject commit 90f52faad22e885e3e29139f236a3b62d019012b
Subproject commit 6faf5464ad85fd6af58f311500c3448fa2a7c884