fixed mime types, cleaned up formats

This commit is contained in:
uh wot 2021-09-02 02:57:42 +02:00
parent bb5ad6c8d7
commit e3104e3cde
Signed by: uhwot
GPG Key ID: CB2454984587B781
3 changed files with 27 additions and 40 deletions

4
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -5,36 +5,20 @@ addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const format_string_to_num = {
aac_96: '8',
64: '10',
128: '1',
320: '3',
flac: '9',
mp4_ra1: '13',
mp4_ra2: '14',
mp4_ra3: '15',
mhm1_ra1: '16',
mhm1_ra2: '17',
mhm1_ra3: '18',
sbc_256: '12',
misc: '0',
}
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',
const formats = {
aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/aac' },
64: { num: '10', gw: 'MP3_64', mime: 'audio/mpeg' },
128: { num: '1', gw: 'MP3_128', mime: 'audio/mpeg' },
320: { num: '3', gw: 'MP3_320', mime: 'audio/mpeg' },
flac: { num: '9', gw: 'FLAC', mime: 'audio/flac' },
mp4_ra1: { num: '13', gw: 'MP4_RA1', mime: 'audio/mp4' },
mp4_ra2: { num: '14', gw: 'MP4_RA2', mime: 'audio/mp4' },
mp4_ra3: { num: '15', gw: 'MP4_RA3', mime: 'audio/mp4' },
mhm1_ra1: { num: '16', gw: 'MHM1_RA1', mime: 'audio/mp4' },
mhm1_ra2: { num: '17', gw: 'MHM1_RA2', mime: 'audio/mp4' },
mhm1_ra3: { num: '18', gw: 'MHM1_RA3', mime: 'audio/mp4' },
sbc_256: { num: '12', gw: 'SBC_256', mime: '' },
misc: { num: '0', gw: 'MP3_MISC', mime: 'audio/mpeg' },
}
async function gw_api_call(method, params) {
@ -107,12 +91,15 @@ async function handler(type, request) {
format = '320'
} else {
format = format.toLowerCase()
if (format_string_to_num[format] === undefined) {
index = Object.values(format_string_to_num).indexOf(format)
if (formats[format] === undefined) {
let nums = []
Object.values(formats).forEach(f => nums.push(f.num))
index = nums.indexOf(format)
if (index === -1) {
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'
}
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' } })
}
@ -162,7 +149,7 @@ async function track(id, format, tagging) {
formats: [
{
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)
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) {
@ -311,7 +298,7 @@ function legacy_track_url(json, format, url_func) {
const md5_origin = json.MD5_ORIGIN
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)
}

View File

@ -6,4 +6,4 @@ workers_dev = true
kv_namespaces = [
{ binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" }
]
vars = { ARL = "haha nope" }
vars = { ARL = "amogus" }