removed struct, made url gen a single function

This commit is contained in:
uh wot 2021-01-25 02:02:47 +01:00
parent b60bdb0384
commit 49dc7869ac
Signed by: uhwot
GPG Key ID: CB2454984587B781
2 changed files with 32 additions and 33 deletions

4
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -7,14 +7,14 @@ addEventListener('fetch', event => {
const AESKEY = [106, 111, 54, 97, 101, 121, 54, 104, 97, 105, 100, 50, 84, 101, 105, 104] const AESKEY = [106, 111, 54, 97, 101, 121, 54, 104, 97, 105, 100, 50, 84, 101, 105, 104]
url_gen = { async function url_gen(md5_origin, format, id, media_version) {
"cipher": new aesjs.ModeOfOperation.ecb(AESKEY), const cipher = new aesjs.ModeOfOperation.ecb(AESKEY)
"resolve": async function(md5_origin, format, id, media_version) { // Track URL generation function
result = [md5_origin, format, id, media_version].join('\xa4') result = [md5_origin, format, id, media_version].join('\xa4')
var buf = new ArrayBuffer(result.length); buf = new ArrayBuffer(result.length);
var result_hash = new Uint8Array(buf); result_hash = new Uint8Array(buf);
for (var i=0; i < result.length; i++) { for (i = 0; i < result.length; i++) {
result_hash[i] = result.charCodeAt(i); result_hash[i] = result.charCodeAt(i);
} }
result_hash = await crypto.subtle.digest('MD5', result_hash) result_hash = await crypto.subtle.digest('MD5', result_hash)
@ -33,13 +33,12 @@ url_gen = {
return item.charCodeAt(0); return item.charCodeAt(0);
}) })
// encryption / hex string // encryption / hex string
result = (result = url_gen.cipher.encrypt(result)).reduce(function(previous, current) { 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 // cdn template with first character of md5 string + hash
return `https://e-cdns-proxy-${md5_origin[0]}.dzcdn.net/api/1/${result}` return `https://e-cdns-proxy-${md5_origin[0]}.dzcdn.net/api/1/${result}`
}
} }
async function track(request) { async function track(request) {
@ -71,7 +70,7 @@ async function track(request) {
const format = "3" const format = "3"
const media_version = json.media_version const media_version = json.media_version
const url = await url_gen.resolve(md5_origin, format, id, media_version) const url = await url_gen(md5_origin, format, id, media_version)
return new Response(null, {status: 302, headers: {'location': url}}) return new Response(null, {status: 302, headers: {'location': url}})
} }