don't get nor renew cookie/token stuff on m3u8 playlists

This commit is contained in:
uh wot 2021-11-10 00:41:36 +01:00
parent 1a802e7654
commit ecd5fd3f8b
Signed by: uhwot
GPG Key ID: CB2454984587B781
2 changed files with 32 additions and 29 deletions

2
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -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')
if (license_token === null) { sid = await KV.get('sid')
const user_data = await gw_api_call('deezer.getUserData')
if (user_data.constructor.name === 'Response') { if (license_token === null) {
return user_data 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 })
} }
} else {
if (user_data.USER.USER_ID === 0) { access_token = await KV.get('access_token')
return new Response('Invalid arl', { status: 500, headers: { 'content-type': 'text/plain' } }) 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) })
} }
} }