Browse Source

feat(storage): Pass over config to worker thread on decryption call

(cherry picked from commit 36d616398eac4e8d51863863fa5205fe1c91267f)
20230320
Jixun Wu 3 years ago
committed by MengYX
parent
commit
5e6cf8bf24
No known key found for this signature in database GPG Key ID: E63F9C7303E8F604
  1. 3
      src/component/FileSelector.vue
  2. 9
      src/decrypt/common.ts

3
src/component/FileSelector.vue

@ -39,6 +39,7 @@
import { spawn, Worker, Pool } from 'threads'; import { spawn, Worker, Pool } from 'threads';
import { CommonDecrypt } from '@/decrypt/common.ts'; import { CommonDecrypt } from '@/decrypt/common.ts';
import { DecryptQueue } from '@/utils/utils'; import { DecryptQueue } from '@/utils/utils';
import { storage } from '@/utils/storage';
export default { export default {
name: 'FileSelector', name: 'FileSelector',
@ -76,7 +77,7 @@ export default {
this.queue.queue(async (dec = CommonDecrypt) => { this.queue.queue(async (dec = CommonDecrypt) => {
console.log('start handling', file.name); console.log('start handling', file.name);
try { try {
this.$emit('success', await dec(file)); this.$emit('success', await dec(file, await storage.getAll()));
} catch (e) { } catch (e) {
console.error(e); console.error(e);
this.$emit('error', e, file.name); this.$emit('error', e, file.name);

9
src/decrypt/common.ts

@ -10,8 +10,15 @@ import { Decrypt as TmDecrypt } from '@/decrypt/tm';
import { Decrypt as JooxDecrypt } from '@/decrypt/joox'; import { Decrypt as JooxDecrypt } from '@/decrypt/joox';
import { DecryptResult, FileInfo } from '@/decrypt/entity'; import { DecryptResult, FileInfo } from '@/decrypt/entity';
import { SplitFilename } from '@/decrypt/utils'; import { SplitFilename } from '@/decrypt/utils';
import { storage } from '@/utils/storage';
import InMemoryStorage from '@/utils/storage/InMemoryStorage';
export async function CommonDecrypt(file: FileInfo, config: Record<string, any>): Promise<DecryptResult> {
// Worker thread will fallback to in-memory storage.
if (storage instanceof InMemoryStorage) {
await storage.setAll(config);
}
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
const raw = SplitFilename(file.name); const raw = SplitFilename(file.name);
let rt_data: DecryptResult; let rt_data: DecryptResult;
switch (raw.ext) { switch (raw.ext) {

Loading…
Cancel
Save