2021-08-16 16:20:14 +02:00
|
|
|
export interface SyncTargetInfo {
|
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
label: string;
|
|
|
|
supportsSelfHosted: boolean;
|
|
|
|
supportsConfigCheck: boolean;
|
2022-04-03 20:19:24 +02:00
|
|
|
supportsRecursiveLinkedNotes: boolean;
|
2021-08-16 16:20:14 +02:00
|
|
|
description: string;
|
|
|
|
classRef: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class SyncTargetRegistry {
|
|
|
|
|
|
|
|
private static reg_: Record<number, SyncTargetInfo> = {};
|
|
|
|
|
2021-08-16 17:18:32 +02:00
|
|
|
private static get reg() {
|
|
|
|
return this.reg_;
|
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static classById(syncTargetId: number) {
|
2021-08-16 17:18:32 +02:00
|
|
|
const info = SyncTargetRegistry.reg[syncTargetId];
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!info) throw new Error(`Invalid id: ${syncTargetId}`);
|
2017-11-24 20:59:16 +02:00
|
|
|
return info.classRef;
|
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static infoByName(name: string): SyncTargetInfo {
|
2021-08-16 17:18:32 +02:00
|
|
|
for (const [, info] of Object.entries(this.reg)) {
|
2021-08-16 16:20:14 +02:00
|
|
|
if (info.name === name) return info;
|
|
|
|
}
|
|
|
|
throw new Error(`Unknown name: ${name}`);
|
|
|
|
}
|
|
|
|
|
2022-04-03 20:19:24 +02:00
|
|
|
public static infoById(id: number): SyncTargetInfo {
|
|
|
|
return this.infoByName(this.idToName(id));
|
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static addClass(SyncTargetClass: any) {
|
2021-08-16 17:18:32 +02:00
|
|
|
this.reg[SyncTargetClass.id()] = {
|
2017-11-24 20:59:16 +02:00
|
|
|
id: SyncTargetClass.id(),
|
2017-11-24 21:21:30 +02:00
|
|
|
name: SyncTargetClass.targetName(),
|
2017-11-24 20:59:16 +02:00
|
|
|
label: SyncTargetClass.label(),
|
|
|
|
classRef: SyncTargetClass,
|
2021-08-16 16:20:14 +02:00
|
|
|
description: SyncTargetClass.description(),
|
|
|
|
supportsSelfHosted: SyncTargetClass.supportsSelfHosted(),
|
2018-02-06 20:59:36 +02:00
|
|
|
supportsConfigCheck: SyncTargetClass.supportsConfigCheck(),
|
2022-04-03 20:19:24 +02:00
|
|
|
supportsRecursiveLinkedNotes: SyncTargetClass.supportsRecursiveLinkedNotes(),
|
2017-11-24 20:59:16 +02:00
|
|
|
};
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static allIds() {
|
2021-08-16 17:18:32 +02:00
|
|
|
return Object.keys(this.reg);
|
2021-05-03 12:55:38 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static nameToId(name: string) {
|
2021-08-16 17:18:32 +02:00
|
|
|
for (const n in this.reg) {
|
|
|
|
if (!this.reg.hasOwnProperty(n)) continue;
|
|
|
|
if (this.reg[n].name === name) return this.reg[n].id;
|
2017-11-24 21:21:30 +02:00
|
|
|
}
|
2021-06-03 17:12:07 +02:00
|
|
|
throw new Error(`Name not found: ${name}. Was the sync target registered?`);
|
2017-11-24 21:21:30 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static idToMetadata(id: number) {
|
2021-08-16 17:18:32 +02:00
|
|
|
for (const n in this.reg) {
|
|
|
|
if (!this.reg.hasOwnProperty(n)) continue;
|
|
|
|
if (this.reg[n].id === id) return this.reg[n];
|
2018-01-25 21:01:14 +02:00
|
|
|
}
|
2019-09-19 23:51:18 +02:00
|
|
|
throw new Error(`ID not found: ${id}`);
|
2018-01-25 21:01:14 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static idToName(id: number) {
|
2018-01-25 23:15:58 +02:00
|
|
|
return this.idToMetadata(id).name;
|
|
|
|
}
|
|
|
|
|
2021-08-16 16:20:14 +02:00
|
|
|
public static idAndLabelPlainObject(os: string) {
|
|
|
|
const output: Record<string, string> = {};
|
2021-08-16 17:18:32 +02:00
|
|
|
for (const n in this.reg) {
|
|
|
|
if (!this.reg.hasOwnProperty(n)) continue;
|
|
|
|
const info = this.reg[n];
|
2020-02-08 13:59:19 +02:00
|
|
|
if (info.classRef.unsupportedPlatforms().indexOf(os) >= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
output[n] = info.label;
|
2017-11-24 21:21:30 +02:00
|
|
|
}
|
2021-08-16 17:18:32 +02:00
|
|
|
|
2017-11-24 21:21:30 +02:00
|
|
|
return output;
|
2022-05-05 14:19:23 +02:00
|
|
|
}
|
2021-08-16 17:18:32 +02:00
|
|
|
|
2022-05-05 14:19:23 +02:00
|
|
|
public static optionsOrder(): string[] {
|
|
|
|
return [
|
|
|
|
'0', // None
|
|
|
|
'10', // Joplin Cloud
|
|
|
|
'7', // Dropbox
|
|
|
|
'3', // OneDrive
|
|
|
|
];
|
2017-11-24 21:21:30 +02:00
|
|
|
}
|
2022-05-05 14:19:23 +02:00
|
|
|
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|