mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-03 08:35:29 +02:00
0765cf5955
- Joplin Server: Adds support for sharing a notebook - Desktop: Adds support for sharing a notebook with Joplin Server - Mobile: Adds support for reading and writing to a shared notebook (not possible to share a notebook) - Cli: Adds support for reading and writing to a shared notebook (not possible to share a notebook)
96 lines
2.3 KiB
TypeScript
96 lines
2.3 KiB
TypeScript
import FileApiDriverJoplinServer from './file-api-driver-joplinServer';
|
|
import Setting from './models/Setting';
|
|
import Synchronizer from './Synchronizer';
|
|
import { _ } from './locale.js';
|
|
import JoplinServerApi from './JoplinServerApi';
|
|
import BaseSyncTarget from './BaseSyncTarget';
|
|
import { FileApi } from './file-api';
|
|
|
|
interface FileApiOptions {
|
|
path(): string;
|
|
username(): string;
|
|
password(): string;
|
|
}
|
|
|
|
export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
|
|
|
public static id() {
|
|
return 9;
|
|
}
|
|
|
|
public static supportsConfigCheck() {
|
|
return true;
|
|
}
|
|
|
|
public static targetName() {
|
|
return 'joplinServer';
|
|
}
|
|
|
|
public static label() {
|
|
return `${_('Joplin Server')} (Beta)`;
|
|
}
|
|
|
|
public async isAuthenticated() {
|
|
return true;
|
|
}
|
|
|
|
public async fileApi(): Promise<FileApi> {
|
|
return super.fileApi();
|
|
}
|
|
|
|
private static async newFileApi_(options: FileApiOptions) {
|
|
const apiOptions = {
|
|
baseUrl: () => options.path(),
|
|
username: () => options.username(),
|
|
password: () => options.password(),
|
|
env: Setting.value('env'),
|
|
};
|
|
|
|
const api = new JoplinServerApi(apiOptions);
|
|
const driver = new FileApiDriverJoplinServer(api);
|
|
const fileApi = new FileApi('', driver);
|
|
fileApi.setSyncTargetId(this.id());
|
|
await fileApi.initialize();
|
|
return fileApi;
|
|
}
|
|
|
|
public static async checkConfig(options: FileApiOptions) {
|
|
const output = {
|
|
ok: false,
|
|
errorMessage: '',
|
|
};
|
|
|
|
try {
|
|
const fileApi = await SyncTargetJoplinServer.newFileApi_(options);
|
|
fileApi.requestRepeatCount_ = 0;
|
|
|
|
await fileApi.put('testing.txt', 'testing');
|
|
const result = await fileApi.get('testing.txt');
|
|
if (result !== 'testing') throw new Error(`Could not access data on server "${options.path()}"`);
|
|
await fileApi.delete('testing.txt');
|
|
output.ok = true;
|
|
} catch (error) {
|
|
output.errorMessage = error.message;
|
|
if (error.code) output.errorMessage += ` (Code ${error.code})`;
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
protected async initFileApi() {
|
|
const fileApi = await SyncTargetJoplinServer.newFileApi_({
|
|
path: () => Setting.value('sync.9.path'),
|
|
username: () => Setting.value('sync.9.username'),
|
|
password: () => Setting.value('sync.9.password'),
|
|
});
|
|
|
|
fileApi.setLogger(this.logger());
|
|
|
|
return fileApi;
|
|
}
|
|
|
|
protected async initSynchronizer() {
|
|
return new Synchronizer(this.db(), await this.fileApi(), Setting.value('appType'));
|
|
}
|
|
}
|