mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
@@ -1,12 +1,27 @@
|
||||
import { WorkerServerBus } from '~/util/WorkerEventBus';
|
||||
import { DECRYPTION_WORKER_ACTION_NAME } from './constants';
|
||||
|
||||
import type { CryptoFactory } from './crypto/CryptoBase';
|
||||
import { XiamiCrypto } from './crypto/xiami/xiami';
|
||||
|
||||
const bus = new WorkerServerBus();
|
||||
onmessage = bus.onmessage;
|
||||
|
||||
const decryptorFactories: CryptoFactory[] = [
|
||||
// Xiami (*.xm)
|
||||
() => new XiamiCrypto(),
|
||||
];
|
||||
|
||||
bus.addEventHandler(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, async (blobURI) => {
|
||||
const blob = await fetch(blobURI).then((r) => r.arrayBuffer());
|
||||
// TODO: Implement decryptor for blob received here.
|
||||
console.log(blob);
|
||||
return { hello: true };
|
||||
const blob = await fetch(blobURI).then((r) => r.blob());
|
||||
|
||||
for (const factory of decryptorFactories) {
|
||||
const decryptor = factory();
|
||||
if (await decryptor.isSupported(blob)) {
|
||||
const decrypted = await decryptor.decrypt(blob);
|
||||
return { decrypted: URL.createObjectURL(decrypted) };
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('could not decrypt file: no working decryptor found');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user