removed struct, made url gen a single function
This commit is contained in:
parent
b60bdb0384
commit
49dc7869ac
File diff suppressed because one or more lines are too long
17
index.js
17
index.js
|
@ -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]
|
||||
|
||||
url_gen = {
|
||||
"cipher": new aesjs.ModeOfOperation.ecb(AESKEY),
|
||||
"resolve": async function(md5_origin, format, id, media_version) { // Track URL generation function
|
||||
async function url_gen(md5_origin, format, id, media_version) {
|
||||
const cipher = new aesjs.ModeOfOperation.ecb(AESKEY)
|
||||
|
||||
result = [md5_origin, format, id, media_version].join('\xa4')
|
||||
|
||||
var buf = new ArrayBuffer(result.length);
|
||||
var result_hash = new Uint8Array(buf);
|
||||
for (var i=0; i < result.length; i++) {
|
||||
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)
|
||||
|
@ -33,14 +33,13 @@ url_gen = {
|
|||
return item.charCodeAt(0);
|
||||
})
|
||||
// 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);
|
||||
}, '')
|
||||
|
||||
// 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) {
|
||||
const id = request.url.split('/')[4]
|
||||
|
@ -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}})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue