2021-06-03 17:12:07 +02:00
import Setting from './models/Setting' ;
import Synchronizer from './Synchronizer' ;
import { _ } from './locale.js' ;
import BaseSyncTarget from './BaseSyncTarget' ;
import { FileApi } from './file-api' ;
import SyncTargetJoplinServer , { initFileApi } from './SyncTargetJoplinServer' ;
interface FileApiOptions {
path ( ) : string ;
2021-06-06 19:14:12 +02:00
userContentPath ( ) : string ;
2021-06-03 17:12:07 +02:00
username ( ) : string ;
password ( ) : string ;
}
export default class SyncTargetJoplinCloud extends BaseSyncTarget {
public static id() {
return 10 ;
}
public static supportsConfigCheck() {
return SyncTargetJoplinServer . supportsConfigCheck ( ) ;
}
public static targetName() {
return 'joplinCloud' ;
}
public static label() {
return _ ( 'Joplin Cloud' ) ;
}
2021-08-16 16:20:14 +02:00
public static description() {
return _ ( 'Joplin\'s own sync service. Also gives access to Joplin-specific features such as publishing notes or collaborating on notebooks with others.' ) ;
}
public static supportsSelfHosted ( ) : boolean {
return false ;
}
2022-04-03 20:19:24 +02:00
public static supportsRecursiveLinkedNotes ( ) : boolean {
2022-08-18 12:39:02 +02:00
// Not currently working:
// https://github.com/laurent22/joplin/pull/6661
// https://github.com/laurent22/joplin/pull/6600
return false ;
2022-04-03 20:19:24 +02:00
}
2024-04-15 19:17:34 +02:00
public static override supportsShare ( ) : boolean {
return true ;
}
2021-06-03 17:12:07 +02:00
public async isAuthenticated() {
2024-03-09 12:35:54 +02:00
try {
const fileApi = await this . fileApi ( ) ;
const api = fileApi . driver ( ) . api ( ) ;
const sessionId = await api . sessionId ( ) ;
return ! ! sessionId ;
} catch ( error ) {
2024-07-01 17:21:17 +02:00
if ( error . code === 403 ) {
return false ;
}
2024-03-09 12:35:54 +02:00
throw error ;
}
}
public authRouteName() {
return 'JoplinCloudLogin' ;
2021-06-03 17:12:07 +02:00
}
2024-07-01 17:21:17 +02:00
// While Joplin Cloud requires password, the new login method makes this
// information useless
2023-08-14 19:12:49 +02:00
public static requiresPassword() {
2024-07-01 17:21:17 +02:00
return false ;
2023-08-14 19:12:49 +02:00
}
2021-06-03 17:12:07 +02:00
public async fileApi ( ) : Promise < FileApi > {
return super . fileApi ( ) ;
}
public static async checkConfig ( options : FileApiOptions ) {
return SyncTargetJoplinServer . checkConfig ( {
. . . options ,
2021-06-08 01:34:33 +02:00
} , SyncTargetJoplinCloud . id ( ) ) ;
2021-06-03 17:12:07 +02:00
}
protected async initFileApi() {
2021-06-08 01:34:33 +02:00
return initFileApi ( SyncTargetJoplinCloud . id ( ) , this . logger ( ) , {
2021-06-03 17:12:07 +02:00
path : ( ) = > Setting . value ( 'sync.10.path' ) ,
2021-06-06 19:14:12 +02:00
userContentPath : ( ) = > Setting . value ( 'sync.10.userContentPath' ) ,
2021-06-03 17:12:07 +02:00
username : ( ) = > Setting . value ( 'sync.10.username' ) ,
password : ( ) = > Setting . value ( 'sync.10.password' ) ,
} ) ;
}
protected async initSynchronizer() {
return new Synchronizer ( this . db ( ) , await this . fileApi ( ) , Setting . value ( 'appType' ) ) ;
}
}