fixed mime types, cleaned up formats
This commit is contained in:
parent
bb5ad6c8d7
commit
e3104e3cde
File diff suppressed because one or more lines are too long
61
index.js
61
index.js
|
@ -5,36 +5,20 @@ addEventListener('fetch', event => {
|
||||||
event.respondWith(handleRequest(event.request))
|
event.respondWith(handleRequest(event.request))
|
||||||
})
|
})
|
||||||
|
|
||||||
const format_string_to_num = {
|
const formats = {
|
||||||
aac_96: '8',
|
aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/aac' },
|
||||||
64: '10',
|
64: { num: '10', gw: 'MP3_64', mime: 'audio/mpeg' },
|
||||||
128: '1',
|
128: { num: '1', gw: 'MP3_128', mime: 'audio/mpeg' },
|
||||||
320: '3',
|
320: { num: '3', gw: 'MP3_320', mime: 'audio/mpeg' },
|
||||||
flac: '9',
|
flac: { num: '9', gw: 'FLAC', mime: 'audio/flac' },
|
||||||
mp4_ra1: '13',
|
mp4_ra1: { num: '13', gw: 'MP4_RA1', mime: 'audio/mp4' },
|
||||||
mp4_ra2: '14',
|
mp4_ra2: { num: '14', gw: 'MP4_RA2', mime: 'audio/mp4' },
|
||||||
mp4_ra3: '15',
|
mp4_ra3: { num: '15', gw: 'MP4_RA3', mime: 'audio/mp4' },
|
||||||
mhm1_ra1: '16',
|
mhm1_ra1: { num: '16', gw: 'MHM1_RA1', mime: 'audio/mp4' },
|
||||||
mhm1_ra2: '17',
|
mhm1_ra2: { num: '17', gw: 'MHM1_RA2', mime: 'audio/mp4' },
|
||||||
mhm1_ra3: '18',
|
mhm1_ra3: { num: '18', gw: 'MHM1_RA3', mime: 'audio/mp4' },
|
||||||
sbc_256: '12',
|
sbc_256: { num: '12', gw: 'SBC_256', mime: '' },
|
||||||
misc: '0',
|
misc: { num: '0', gw: 'MP3_MISC', mime: 'audio/mpeg' },
|
||||||
}
|
|
||||||
|
|
||||||
const format_string_to_gw = {
|
|
||||||
aac_96: 'AAC_96',
|
|
||||||
64: 'MP3_64',
|
|
||||||
128: 'MP3_128',
|
|
||||||
320: 'MP3_320',
|
|
||||||
flac: 'FLAC',
|
|
||||||
mp4_ra1: 'MP4_RA1',
|
|
||||||
mp4_ra2: 'MP4_RA2',
|
|
||||||
mp4_ra3: 'MP4_RA3',
|
|
||||||
mhm1_ra1: 'MHM1_RA1',
|
|
||||||
mhm1_ra2: 'MHM1_RA2',
|
|
||||||
mhm1_ra3: 'MHM1_RA3',
|
|
||||||
sbc_256: 'SBC_256',
|
|
||||||
misc: 'MP3_MISC',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gw_api_call(method, params) {
|
async function gw_api_call(method, params) {
|
||||||
|
@ -107,12 +91,15 @@ async function handler(type, request) {
|
||||||
format = '320'
|
format = '320'
|
||||||
} else {
|
} else {
|
||||||
format = format.toLowerCase()
|
format = format.toLowerCase()
|
||||||
if (format_string_to_num[format] === undefined) {
|
if (formats[format] === undefined) {
|
||||||
index = Object.values(format_string_to_num).indexOf(format)
|
let nums = []
|
||||||
|
Object.values(formats).forEach(f => nums.push(f.num))
|
||||||
|
|
||||||
|
index = nums.indexOf(format)
|
||||||
if (index === -1) {
|
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]
|
format = Object.keys(formats)[index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +125,7 @@ async function track(id, format, tagging) {
|
||||||
format = 'misc'
|
format = 'misc'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json['FILESIZE_' + format_string_to_gw[format]] == false) {
|
if (json['FILESIZE_' + formats[format].gw] == false) {
|
||||||
return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } })
|
return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +149,7 @@ async function track(id, format, tagging) {
|
||||||
formats: [
|
formats: [
|
||||||
{
|
{
|
||||||
cipher: 'BF_CBC_STRIPE',
|
cipher: 'BF_CBC_STRIPE',
|
||||||
format: format_string_to_gw[format]
|
format: formats[format].gw
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -263,7 +250,7 @@ async function track(id, format, tagging) {
|
||||||
|
|
||||||
pipeDecryptedStream(writer, track.body, length, cipher)
|
pipeDecryptedStream(writer, track.body, length, cipher)
|
||||||
|
|
||||||
return new Response(readable, { status: 200, headers: { 'content-type': 'audio/mpeg' } })
|
return new Response(readable, { status: 200, headers: { 'content-type': formats[format].mime } })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pipeDecryptedStream(writer, body, length, cipher) {
|
async function pipeDecryptedStream(writer, body, length, cipher) {
|
||||||
|
@ -311,7 +298,7 @@ function legacy_track_url(json, format, url_func) {
|
||||||
const md5_origin = json.MD5_ORIGIN
|
const md5_origin = json.MD5_ORIGIN
|
||||||
const media_version = json.MEDIA_VERSION
|
const media_version = json.MEDIA_VERSION
|
||||||
|
|
||||||
format = format_string_to_num[format]
|
format = formats[format].num
|
||||||
|
|
||||||
return url_func(md5_origin, format, id, media_version)
|
return url_func(md5_origin, format, id, media_version)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ workers_dev = true
|
||||||
kv_namespaces = [
|
kv_namespaces = [
|
||||||
{ binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" }
|
{ binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" }
|
||||||
]
|
]
|
||||||
vars = { ARL = "haha nope" }
|
vars = { ARL = "amogus" }
|
Loading…
Reference in New Issue