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
59
index.js
59
index.js
|
@ -69,36 +69,39 @@ async function handler(type, request) {
|
|||
const url = new URL(request.url)
|
||||
const id = url.pathname.split('/')[2]
|
||||
|
||||
if (id[0] !== '-') { // checks if not user-upped track
|
||||
license_token = await KV.get('license_token')
|
||||
checkForm = await KV.get('checkForm')
|
||||
sid = await KV.get('sid')
|
||||
|
||||
if (license_token === null) {
|
||||
const user_data = await gw_api_call('deezer.getUserData')
|
||||
if (user_data.constructor.name === 'Response') {
|
||||
return user_data
|
||||
// cookie/token stuff isn't needed for m3u8 playlists
|
||||
if (type === 'track') {
|
||||
if (id[0] !== '-') { // checks if not user-upped track
|
||||
license_token = await KV.get('license_token')
|
||||
checkForm = await KV.get('checkForm')
|
||||
sid = await KV.get('sid')
|
||||
|
||||
if (license_token === null) {
|
||||
const user_data = await gw_api_call('deezer.getUserData')
|
||||
if (user_data.constructor.name === 'Response') {
|
||||
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 })
|
||||
}
|
||||
|
||||
if (user_data.USER.USER_ID === 0) {
|
||||
return new Response('Invalid arl', { status: 500, headers: { 'content-type': 'text/plain' } })
|
||||
} 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) })
|
||||
}
|
||||
|
||||
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