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
61
index.js
61
index.js
|
@ -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]
|
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')
|
|
||||||
|
|
||||||
var buf = new ArrayBuffer(result.length);
|
result = [md5_origin, format, id, media_version].join('\xa4')
|
||||||
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 = result_hash + '\xa4' + result + '\xa4'
|
buf = new ArrayBuffer(result.length);
|
||||||
|
result_hash = new Uint8Array(buf);
|
||||||
// padding
|
for (i = 0; i < result.length; i++) {
|
||||||
result += '\x00'.repeat(result.length % 16 ? 16 - result.length % 16 : 0)
|
result_hash[i] = result.charCodeAt(i);
|
||||||
|
|
||||||
// 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}`
|
|
||||||
}
|
}
|
||||||
|
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) {
|
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}})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue