Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 lines
1.2 KiB

import { webp2png } from './webp';
import type { WebpConvertTask } from './webpWorkerController';
const ctx = self as any as DedicatedWorkerGlobalScope;
const tasks: WebpConvertTask[] = [];
//let isProcessing = false;
function finishTask() {
//isProcessing = false;
processTasks();
}
function processTasks() {
//if(isProcessing) return;
const task = tasks.shift();
if(!task) return;
//isProcessing = true;
switch(task.type) {
case 'convertWebp': {
const {fileName, bytes} = task.payload;
let convertedBytes: Uint8Array;
try {
convertedBytes = webp2png(bytes).bytes;
} catch(err) {
console.error('Convert webp2png error:', err, 'payload:', task.payload);
}
ctx.postMessage({
type: 'convertWebp',
payload: {
fileName,
bytes: convertedBytes
}
});
finishTask();
break;
}
default:
finishTask();
}
}
function scheduleTask(task: WebpConvertTask) {
tasks.push(task);
/* if(task.payload.fileName.indexOf('main-') === 0) {
tasks.push(task);
} else {
tasks.unshift(task);
} */
processTasks();
}
ctx.addEventListener('message', (event) => {
scheduleTask(event.data);
});