From eaf457e6a07934c1eef4a6152851d319e640d520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Mon, 20 Dec 2021 22:22:35 +0000 Subject: [PATCH] feat(storage): Pass over config to worker thread on decryption call (cherry picked from commit 36d616398eac4e8d51863863fa5205fe1c91267f) --- src/component/FileSelector.vue | 3 ++- src/decrypt/common.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/component/FileSelector.vue b/src/component/FileSelector.vue index 1ae82ac..cd78cdb 100644 --- a/src/component/FileSelector.vue +++ b/src/component/FileSelector.vue @@ -39,6 +39,7 @@ import { spawn, Worker, Pool } from 'threads'; import { CommonDecrypt } from '@/decrypt/common.ts'; import { DecryptQueue } from '@/utils/utils'; +import { storage } from '@/utils/storage'; export default { name: 'FileSelector', @@ -76,7 +77,7 @@ export default { this.queue.queue(async (dec = CommonDecrypt) => { console.log('start handling', file.name); try { - this.$emit('success', await dec(file)); + this.$emit('success', await dec(file, await storage.getAll())); } catch (e) { console.error(e); this.$emit('error', e, file.name); diff --git a/src/decrypt/common.ts b/src/decrypt/common.ts index 03d3a39..ca570df 100644 --- a/src/decrypt/common.ts +++ b/src/decrypt/common.ts @@ -10,8 +10,15 @@ import { Decrypt as TmDecrypt } from '@/decrypt/tm'; import { Decrypt as JooxDecrypt } from '@/decrypt/joox'; import { DecryptResult, FileInfo } from '@/decrypt/entity'; import { SplitFilename } from '@/decrypt/utils'; +import { storage } from '@/utils/storage'; +import InMemoryStorage from '@/utils/storage/InMemoryStorage'; + +export async function CommonDecrypt(file: FileInfo, config: Record): Promise { + // Worker thread will fallback to in-memory storage. + if (storage instanceof InMemoryStorage) { + await storage.setAll(config); + } -export async function CommonDecrypt(file: FileInfo): Promise { const raw = SplitFilename(file.name); let rt_data: DecryptResult; switch (raw.ext) {