You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
All: Decryption worker and handling of missing master key passwords
This commit is contained in:
@ -1,13 +1,57 @@
|
||||
const BaseItem = require('lib/models/BaseItem');
|
||||
|
||||
class DecryptionWorker {
|
||||
|
||||
constructor() {
|
||||
this.state_ = 'idle';
|
||||
|
||||
this.dispatch = (action) => {
|
||||
console.warn('DecryptionWorker.dispatch is not defined');
|
||||
};
|
||||
}
|
||||
|
||||
start() {
|
||||
static instance() {
|
||||
if (this.instance_) return this.instance_;
|
||||
this.instance_ = new DecryptionWorker();
|
||||
return this.instance_;
|
||||
}
|
||||
|
||||
static encryptionService() {
|
||||
if (!this.encryptionService_) throw new Error('DecryptionWorker.encryptionService_ is not set!!');
|
||||
return this.encryptionService_;
|
||||
}
|
||||
|
||||
async start() {
|
||||
if (this.state_ !== 'idle') return;
|
||||
|
||||
this.state_ = 'started';
|
||||
|
||||
let excludedIds = [];
|
||||
|
||||
while (true) {
|
||||
const result = await BaseItem.itemsThatNeedDecryption(excludedIds);
|
||||
const items = result.items;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
const ItemClass = BaseItem.itemClass(item);
|
||||
try {
|
||||
await ItemClass.decrypt(item);
|
||||
} catch (error) {
|
||||
if (error.code === 'missingMasterKey') {
|
||||
excludedIds.push(item.id);
|
||||
this.dispatch({
|
||||
type: 'MASTERKEY_ADD_MISSING',
|
||||
id: error.masterKeyId,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.hasMore) break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user