don't get nor renew cookie/token stuff on m3u8 playlists
This commit is contained in:
parent
1a802e7654
commit
ecd5fd3f8b
File diff suppressed because one or more lines are too long
55
index.js
55
index.js
|
@ -69,36 +69,39 @@ async function handler(type, request) {
|
||||||
const url = new URL(request.url)
|
const url = new URL(request.url)
|
||||||
const id = url.pathname.split('/')[2]
|
const id = url.pathname.split('/')[2]
|
||||||
|
|
||||||
if (id[0] !== '-') { // checks if not user-upped track
|
// cookie/token stuff isn't needed for m3u8 playlists
|
||||||
license_token = await KV.get('license_token')
|
if (type === 'track') {
|
||||||
checkForm = await KV.get('checkForm')
|
if (id[0] !== '-') { // checks if not user-upped track
|
||||||
sid = await KV.get('sid')
|
license_token = await KV.get('license_token')
|
||||||
|
checkForm = await KV.get('checkForm')
|
||||||
|
sid = await KV.get('sid')
|
||||||
|
|
||||||
if (license_token === null) {
|
if (license_token === null) {
|
||||||
const user_data = await gw_api_call('deezer.getUserData')
|
const user_data = await gw_api_call('deezer.getUserData')
|
||||||
if (user_data.constructor.name === 'Response') {
|
if (user_data.constructor.name === 'Response') {
|
||||||
return user_data
|
return user_data
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user_data.USER.USER_ID === 0) {
|
||||||
|
return new Response('Invalid arl', { status: 500, headers: { 'content-type': 'text/plain' } })
|
||||||
|
}
|
||||||
|
|
||||||
|
license_token = user_data.USER.OPTIONS.license_token
|
||||||
|
|
||||||
|
await KV.put('license_token', license_token, { expirationTtl: 3600 })
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
access_token = await KV.get('access_token')
|
||||||
|
if (access_token === null) {
|
||||||
|
const response = await fetch(`https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=${client_id}&client_secret=${client_secret}&output=json`)
|
||||||
|
const json = await response.json()
|
||||||
|
if (json.error !== undefined) {
|
||||||
|
return new Response("Couldn't get access token from Deezer", { status: 500, headers: { 'content-type': 'text/plain' } })
|
||||||
|
}
|
||||||
|
|
||||||
if (user_data.USER.USER_ID === 0) {
|
access_token = json.access_token
|
||||||
return new Response('Invalid arl', { status: 500, headers: { 'content-type': 'text/plain' } })
|
await KV.put('access_token', access_token, { expirationTtl: parseInt(json.expires) })
|
||||||
}
|
}
|
||||||
|
|
||||||
license_token = user_data.USER.OPTIONS.license_token
|
|
||||||
|
|
||||||
await KV.put('license_token', license_token, { expirationTtl: 3600 })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
access_token = await KV.get('access_token')
|
|
||||||
if (access_token === null) {
|
|
||||||
const response = await fetch(`https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=${client_id}&client_secret=${client_secret}&output=json`)
|
|
||||||
const json = await response.json()
|
|
||||||
if (json.error !== undefined) {
|
|
||||||
return new Response("Couldn't get access token from Deezer", { status: 500, headers: { 'content-type': 'text/plain' } })
|
|
||||||
}
|
|
||||||
|
|
||||||
access_token = json.access_token
|
|
||||||
await KV.put('access_token', access_token, { expirationTtl: parseInt(json.expires) })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue