added some error handling, updated deps, cleaned up code
This commit is contained in:
parent
fd54890190
commit
344175d002
|
@ -14,7 +14,7 @@ aes = "0.7"
|
||||||
md-5 = "0.9"
|
md-5 = "0.9"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
|
||||||
wasm-bindgen = "=0.2.74"
|
wasm-bindgen = "0.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3"
|
wasm-bindgen-test = "0.3"
|
||||||
|
|
File diff suppressed because one or more lines are too long
16
index.js
16
index.js
|
@ -130,8 +130,9 @@ async function track(id, format, tagging) {
|
||||||
|
|
||||||
const wasm = await import('./pkg')
|
const wasm = await import('./pkg')
|
||||||
|
|
||||||
legacy_url = !['320', 'flac'].includes(format)
|
let track_url
|
||||||
if (!legacy_url) { // server-side stream 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
|
// needed if track has fallback, like https://www.deezer.com/track/11835714
|
||||||
let track_token
|
let track_token
|
||||||
if (json.FALLBACK !== undefined) {
|
if (json.FALLBACK !== undefined) {
|
||||||
|
@ -168,12 +169,13 @@ async function track(id, format, tagging) {
|
||||||
|
|
||||||
const media_json = await resp.json()
|
const media_json = await resp.json()
|
||||||
|
|
||||||
result = media_json.data[0].media[0].sources[0].url
|
if (media_json.data[0].media !== undefined) {
|
||||||
} else { // legacy stream url
|
track_url = media_json.data[0].media[0].sources[0].url
|
||||||
result = await legacy_track_url(json, format, wasm.legacy_stream_url)
|
} else {
|
||||||
if (typeof result === 'object') {
|
return new Response("Couldn't get stream URL", { status: 403, headers: { 'content-type': 'text/plain' } })
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
} else { // legacy stream url
|
||||||
|
track_url = await legacy_track_url(json, format, wasm.legacy_stream_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
const track = await fetch(result)
|
const track = await fetch(result)
|
||||||
|
|
Loading…
Reference in New Issue