fixed format for user-uploaded tracks in playlists, made quotes consistent

This commit is contained in:
uh wot 2021-01-26 16:02:54 +01:00
parent 40680506ae
commit e8e6b78ce9
Signed by: uhwot
GPG Key ID: CB2454984587B781
2 changed files with 16 additions and 16 deletions

2
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,7 @@ async function url_gen(md5_origin, format, id, media_version) {
result_hash = await crypto.subtle.digest('MD5', result_hash)
result_hash = Array.from(new Uint8Array(result_hash))
result_hash = result_hash.reduce(function(previous, current) {
return previous + "0".concat(current.toString(16)).substr(-2, 2);
return previous + '0'.concat(current.toString(16)).substr(-2, 2);
}, ''),
result = result_hash + '\xa4' + result + '\xa4'
@ -34,7 +34,7 @@ async function url_gen(md5_origin, format, id, media_version) {
})
// encryption / hex string
result = (result = cipher.encrypt(result)).reduce(function(previous, current) {
return previous + "0".concat(current.toString(16)).substr(-2, 2);
return previous + '0'.concat(current.toString(16)).substr(-2, 2);
}, '')
// cdn template with first character of md5 string + hash
@ -50,38 +50,34 @@ const format_string_to_num = {
}
async function handler(type, request) {
access_token = await KV.get("access_token")
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=447462&client_secret=a83bf7f38ad2f137e444727cfc3775cf&output=json")
const response = await fetch('https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=447462&client_secret=a83bf7f38ad2f137e444727cfc3775cf&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"}})
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: Number(json.expires)})
await KV.put('access_token', access_token, {expirationTtl: Number(json.expires)})
}
const url = new URL(request.url)
const id = url.pathname.split('/')[2]
if (id === "") {
return new Response("ID needs to be specified", {status: 400, headers: {'content-type': "text/plain"}})
return new Response('ID needs to be specified', {status: 400, headers: {'content-type': 'text/plain'}})
}
format = url.searchParams.get('f')
if (format === null) {
if (!(id[0] === '-')) {
format = '320'
} else {
format = 'misc' // user-uploaded tracks
}
} else {
format = format.toLowerCase()
if (format_string_to_num[format] === undefined) {
index = Object.values(format_string_to_num).indexOf(format)
if (index === -1) {
return new Response("Invalid format", {status: 400, headers: {'content-type': "text/plain"}})
return new Response('Invalid format', {status: 400, headers: {'content-type': 'text/plain'}})
}
format = Object.keys(format_string_to_num)[index]
}
@ -116,8 +112,12 @@ async function track_url(json, format) {
const md5_origin = json.md5_origin
const media_version = json.media_version
if (id < 0) {
format = 'misc'
}
if (json['filesize_' + format] === '0') {
return new Response("Format unavailable", {status: 403, headers: {'content-type': "text/plain"}})
return new Response('Format unavailable', {status: 403, headers: {'content-type': 'text/plain'}})
}
format = format_string_to_num[format]
@ -132,7 +132,7 @@ async function m3u8(type, id, format, access_token) {
return new Response(JSON.stringify(json.error), {status: 403, headers: {'content-type': "application/json"}})
}
var list = "#EXTM3U\n"
var list = '#EXTM3U\n'
for (const track of json.tracks.data) {
const result = await track_url(track, format)