mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-13 19:42:36 +02:00
All: Fixed filesystem driver bug when downloading resources. Added support for encrypting all items when encryption enabled.
This commit is contained in:
parent
e9bb5bee9d
commit
f5d26e0d81
@ -146,11 +146,17 @@ class FileApiDriverLocal {
|
||||
let output = null;
|
||||
|
||||
try {
|
||||
if (options.encoding == 'binary') {
|
||||
output = fs.readFile(path);
|
||||
if (options.target === 'file') {
|
||||
output = await fs.copy(path, options.path, { overwrite: true });
|
||||
} else {
|
||||
output = fs.readFile(path, options.encoding);
|
||||
output = await fs.readFile(path, options.encoding);
|
||||
}
|
||||
|
||||
// if (options.encoding == 'binary') {
|
||||
// output = await fs.readFile(path);
|
||||
// } else {
|
||||
// output = await fs.readFile(path, options.encoding);
|
||||
// }
|
||||
} catch (error) {
|
||||
if (error.code == 'ENOENT') return null;
|
||||
throw this.fsErrorToJsError_(error);
|
||||
|
@ -290,6 +290,8 @@ class JoplinDatabase extends Database {
|
||||
queries.push('ALTER TABLE ' + n + ' ADD COLUMN encryption_applied INT NOT NULL DEFAULT 0');
|
||||
queries.push('CREATE INDEX ' + n + '_encryption_applied ON ' + n + ' (encryption_applied)');
|
||||
}
|
||||
|
||||
queries.push('ALTER TABLE sync_items ADD COLUMN force_sync INT NOT NULL DEFAULT 0');
|
||||
}
|
||||
|
||||
queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] });
|
||||
|
@ -424,7 +424,7 @@ class BaseItem extends BaseModel {
|
||||
SELECT %s FROM %s items
|
||||
JOIN sync_items s ON s.item_id = items.id
|
||||
WHERE sync_target = %d
|
||||
AND s.sync_time < items.updated_time
|
||||
AND (s.sync_time < items.updated_time OR force_sync = 1)
|
||||
AND s.sync_disabled = 0
|
||||
%s
|
||||
LIMIT %d
|
||||
@ -546,6 +546,28 @@ class BaseItem extends BaseModel {
|
||||
return !!item.encryption_applied ? '🔑 ' + _('Encrypted') : item.title + '';
|
||||
}
|
||||
|
||||
static async markAllNonEncryptedForSync() {
|
||||
const classNames = this.encryptableItemClassNames();
|
||||
|
||||
for (let i = 0; i < classNames.length; i++) {
|
||||
const className = classNames[i];
|
||||
const ItemClass = this.getClass(className);
|
||||
|
||||
const sql = sprintf(`
|
||||
SELECT id
|
||||
FROM %s
|
||||
WHERE encryption_applied = 0`,
|
||||
this.db().escapeField(ItemClass.tableName()),
|
||||
);
|
||||
|
||||
const items = await ItemClass.modelSelectAll(sql);
|
||||
const ids = items.map((item) => {return item.id});
|
||||
if (!ids.length) continue;
|
||||
|
||||
await this.db().exec('UPDATE sync_items SET force_sync = 1 WHERE item_id IN ("' + ids.join('","') + '")');
|
||||
}
|
||||
}
|
||||
|
||||
static async save(o, options = null) {
|
||||
if (!options) options = {};
|
||||
|
||||
|
@ -2,6 +2,7 @@ const { padLeft } = require('lib/string-utils.js');
|
||||
const { shim } = require('lib/shim.js');
|
||||
const Setting = require('lib/models/Setting.js');
|
||||
const MasterKey = require('lib/models/MasterKey');
|
||||
const BaseItem = require('lib/models/BaseItem');
|
||||
|
||||
function hexPad(s, length) {
|
||||
return padLeft(s, length, '0');
|
||||
@ -41,6 +42,8 @@ class EncryptionService {
|
||||
passwordCache[masterKey.id] = password;
|
||||
Setting.setValue('encryption.passwordCache', passwordCache);
|
||||
}
|
||||
|
||||
await BaseItem.markAllNonEncryptedForSync();
|
||||
}
|
||||
|
||||
async loadMasterKeysFromSettings() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user