feat: add xiami crypto & have a working decryption workflow (#2, #9)

This commit is contained in:
鲁树人 committed 2023-05-09 01:23:35 +01:00
1 parent 5ad054631c
commit 1c1d234244
6 files changed
+109 -7

No files matched your search

+19 -4
View File
@@ -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');
});