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,39 +7,38 @@ addEventListener('fetch', event => {
const AESKEY = [106, 111, 54, 97, 101, 121, 54, 104, 97, 105, 100, 50, 84, 101, 105, 104]
url_gen = {
"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')
async function url_gen(md5_origin, format, id, media_version) {
const cipher = new aesjs.ModeOfOperation.ecb(AESKEY)
var buf = new ArrayBuffer(result.length);
var result_hash = new Uint8Array(buf);
for (var i=0; i < result.length; i++) {
result_hash[i] = result.charCodeAt(i);
}
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);
}, ''),
result = [md5_origin, format, id, media_version].join('\xa4')
result = result_hash + '\xa4' + result + '\xa4'
// padding
result += '\x00'.repeat(result.length % 16 ? 16 - result.length % 16 : 0)
// converting to array for encryption / hex string
result = Array.from(result).map(function(item) {
return item.charCodeAt(0);
})
// encryption / hex string
result = (result = url_gen.cipher.encrypt(result)).reduce(function(previous, current) {
return previous + "0".concat(current.toString(16)).substr(-2, 2);
}, '')
// cdn template with first character of md5 string + hash
return `https://e-cdns-proxy-${md5_origin[0]}.dzcdn.net/api/1/${result}`
buf = new ArrayBuffer(result.length);
result_hash = new Uint8Array(buf);
for (i = 0; i < result.length; i++) {
result_hash[i] = result.charCodeAt(i);
}
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);
}, ''),
result = result_hash + '\xa4' + result + '\xa4'
// padding
result += '\x00'.repeat(result.length % 16 ? 16 - result.length % 16 : 0)
// converting to array for encryption / hex string
result = Array.from(result).map(function(item) {
return item.charCodeAt(0);
})
// encryption / hex string
result = (result = cipher.encrypt(result)).reduce(function(previous, current) {
return previous + "0".concat(current.toString(16)).substr(-2, 2);
}, '')
// cdn template with first character of md5 string + hash
return `https://e-cdns-proxy-${md5_origin[0]}.dzcdn.net/api/1/${result}`
}
async function track(request) {
@ -71,7 +70,7 @@ async function track(request) {
const format = "3"
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}})
}