Initial commit
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
export const decryptTool = {
|
||||
decryptKey: "2019ysapp7527",
|
||||
cachedBlobs: {},
|
||||
// 并发控制
|
||||
maxConcurrency: 10,
|
||||
activeCount: 0,
|
||||
queue: [],
|
||||
/**
|
||||
* @description 图片解密
|
||||
* @param url 需要解密的url
|
||||
* @returns 解密过后的图片链接
|
||||
*/
|
||||
async imgDecypt(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const task = async () => {
|
||||
try {
|
||||
const r = await fetch(url);
|
||||
const rb = await r.arrayBuffer();
|
||||
const blobUrl = this.imgEncrypt(rb);
|
||||
resolve(blobUrl);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
} finally {
|
||||
// 任务完成,减少计数并尝试启动下一个队列任务
|
||||
this.activeCount = Math.max(0, this.activeCount - 1);
|
||||
if (this.queue.length > 0) {
|
||||
const next = this.queue.shift();
|
||||
this.activeCount++;
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (this.activeCount < this.maxConcurrency) {
|
||||
this.activeCount++;
|
||||
task();
|
||||
} else {
|
||||
this.queue.push(task);
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 图片解密
|
||||
* @param buffer buffer
|
||||
* @returns
|
||||
*/
|
||||
imgEncrypt(buffer) {
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const encoder = new TextEncoder();
|
||||
const KEY = encoder.encode(this.decryptKey);
|
||||
for (let i = 0; i < 100; i++) {
|
||||
bytes[i] ^= KEY[i % KEY.length];
|
||||
}
|
||||
const blob = new Blob([bytes], {
|
||||
type: "image/png",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
return url;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user