1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-24 23:26:50 +02:00

Server: Add support for sharing notes via a link

This commit is contained in:
Laurent Cozic
2021-01-29 18:45:11 +00:00
parent 4a847a096b
commit ccbc329cbf
136 changed files with 4713 additions and 5561 deletions

View File

@ -16,6 +16,9 @@ import MasterKey from './models/MasterKey';
import BaseModel from './BaseModel';
const { sprintf } = require('sprintf-js');
import time from './time';
import ResourceService from './services/ResourceService';
import EncryptionService from './services/EncryptionService';
import NoteResource from './models/NoteResource';
const JoplinError = require('./JoplinError');
const TaskQueue = require('./TaskQueue');
const { Dirnames } = require('./services/synchronizer/utils/types');
@ -39,7 +42,8 @@ export default class Synchronizer {
private clientId_: string;
private lockHandler_: LockHandler;
private migrationHandler_: MigrationHandler;
private encryptionService_: any = null;
private encryptionService_: EncryptionService = null;
private resourceService_: ResourceService = null;
private syncTargetIsLocked_: boolean = false;
// Debug flags are used to test certain hard-to-test conditions
@ -104,7 +108,7 @@ export default class Synchronizer {
return this.appType_ === 'mobile' ? 100 * 1000 * 1000 : Infinity;
}
setEncryptionService(v: any) {
public setEncryptionService(v: any) {
this.encryptionService_ = v;
}
@ -112,6 +116,14 @@ export default class Synchronizer {
return this.encryptionService_;
}
public setResourceService(v: ResourceService) {
this.resourceService_ = v;
}
protected resourceService(): ResourceService {
return this.resourceService_;
}
async waitForSyncToFinish() {
if (this.state() === 'idle') return;
@ -220,7 +232,7 @@ export default class Synchronizer {
const iid = shim.setInterval(() => {
if (this.state() == 'idle') {
shim.clearInterval(iid);
resolve();
resolve(null);
}
}, 100);
});
@ -332,6 +344,19 @@ export default class Synchronizer {
return `${Dirnames.Resources}/${resourceId}`;
};
// We index resources and apply the "is_shared" flag before syncing
// because it's going to affect what's sent encrypted, and what's sent
// plain text.
try {
if (this.resourceService()) {
this.logger().info('Indexing resources...');
await this.resourceService().indexNoteResources();
await NoteResource.applySharedStatusToLinkedResources();
}
} catch (error) {
this.logger().error('Error indexing resources:', error);
}
let errorToThrow = null;
let syncLock = null;