fixed fallback handling

This commit is contained in:
uh wot 2021-09-01 16:12:33 +02:00
parent 4b8b3dde44
commit e28ad54c6b
Signed by: uhwot
GPG Key ID: CB2454984587B781
3 changed files with 13 additions and 6 deletions

4
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -66,8 +66,16 @@ async function track(id, format, tagging) {
encrypted = !['320', 'flac'].includes(format)
if (!encrypted) { // server-side stream url
// TODO: handle alternatives
result = json['url_' + format]
// needed if track has fallback, like https://www.deezer.com/track/11835714
let urls
if (!json.alternative) {
urls = json
} else {
const temp = await fetch(`https://api.deezer.com/streaming_url.php?access_token=${ACCESS_TOKEN}&track_id=${json.alternative.id}`)
urls = await temp.json()
}
result = urls['url_' + format]
if (result === undefined) {
return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } })

View File

@ -3,4 +3,3 @@ type = "webpack"
webpack_config = "webpack.config.js"
account_id = "03479b0523a52b140e0dabac40cb0fc8"
workers_dev = true
vars = { ACCESS_TOKEN = "haha nope" }