import { createClient } from "@buttercup/dropbox-client" ; import TextDatasource from "./TextDatasource" ; import { fireInstantiationHandlers , registerDatasource } from "./register" ; import Credentials from "../credentials/Credentials" ; import { getCredentials } from "../credentials/channel" ; import { DatasourceConfigurationDropbox , DatasourceLoadedData , EncryptedContent , History } from "../types" ; augments TextDatasource memberof export default class DropboxDatasource extends TextDatasource { client : any ; path : string ; token : string ; param credentials constructor ( credentials ) { super ( credentials ) ; const { data : credentialData } = getCredentials ( credentials . id ) ; const { datasource : datasourceConfig } = credentialData as { datasource : DatasourceConfigurationDropbox ; } ; const { token , path } = datasourceConfig ; this . path = path ; this . token = token ; this . client = createClient ( token ) ; this . type = "dropbox" ; fireInstantiationHandlers ( "dropbox" , this ) ; } memberof getConfiguration ( ) { return { type : "dropbox" , token : this . token , path : this . path } ; } param credentials returns memberof load ( credentials ) { if ( this . hasContent ) { return super . load ( credentials ) ; } return this . client . getFileContents ( this . path ) . then ( content => { this . setContent ( content ) ; return super . load ( credentials ) ; } ) ; } param history param credentials returns memberof save ( history , credentials ) { return super . save ( history , credentials ) . then ( ( encryptedContent ) => this . client . putFileContents ( this . path , encryptedContent ) ) ; } returns memberof supportsRemoteBypass ( ) { return true ; } } registerDatasource ( "dropbox" , DropboxDatasource ) ;