added some error handling, updated deps, cleaned up code

This commit is contained in:
uh wot 2021-09-12 20:08:31 +02:00
parent fd54890190
commit 344175d002
Signed by: uhwot
GPG Key ID: CB2454984587B781
3 changed files with 11 additions and 9 deletions

View File

@ -14,7 +14,7 @@ aes = "0.7"
md-5 = "0.9"
hex = "0.4"
wasm-bindgen = "=0.2.74"
wasm-bindgen = "0.2"
[dev-dependencies]
wasm-bindgen-test = "0.3"

2
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -130,8 +130,9 @@ async function track(id, format, tagging) {
const wasm = await import('./pkg')
legacy_url = !['320', 'flac'].includes(format)
if (!legacy_url) { // server-side stream url
let track_url
let use_legacy_url = !['320', 'flac'].includes(format)
if (!use_legacy_url) { // server-side stream url
// needed if track has fallback, like https://www.deezer.com/track/11835714
let track_token
if (json.FALLBACK !== undefined) {
@ -168,12 +169,13 @@ async function track(id, format, tagging) {
const media_json = await resp.json()
result = media_json.data[0].media[0].sources[0].url
} else { // legacy stream url
result = await legacy_track_url(json, format, wasm.legacy_stream_url)
if (typeof result === 'object') {
return result
if (media_json.data[0].media !== undefined) {
track_url = media_json.data[0].media[0].sources[0].url
} else {
return new Response("Couldn't get stream URL", { status: 403, headers: { 'content-type': 'text/plain' } })
}
} else { // legacy stream url
track_url = await legacy_track_url(json, format, wasm.legacy_stream_url)
}
const track = await fetch(result)