import { Credentials , DatasourceLoadedData , EncryptedContent , History , TextDatasource , registerDatasource } from "buttercup" ; import { readFile , writeFile } from "react-native-fs" ; import path from "path-browserify" ; import { LocalFileSystemInterface } from "./LocalFileInterface" ; import { DatasourceConfigurationMobileLocalFile } from "../../types" ; function prepareFullPath ( filePath ) { return path . join ( LocalFileSystemInterface . getRootDirectory ( ) , filePath ) ; } export class MobileLocalFileDatasource extends TextDatasource { protected _filename : string ; constructor ( credentials ) { super ( credentials ) ; const { data : credentialsData } = credentials . getData ( ) as any ; const { datasource : datasourceConfig } = credentialsData as { datasource : DatasourceConfigurationMobileLocalFile ; } ; this . _filename = prepareFullPath ( datasourceConfig . filename ) ; this . type = "mobilelocalfile" ; } getConfiguration ( ) { return { type : this . type , path : this . _filename } ; } async load ( credentials ) { const enc = await readFile ( this . _filename ) ; this . setContent ( enc ) ; return super . load ( credentials ) ; } async save ( history , credentials ) { const encrypted = await super . save ( history , credentials ) ; await writeFile ( this . _filename , encrypted ) ; return encrypted ; } supportsAttachments ( ) { return false ; } supportsRemoteBypass ( ) { return false ; } } registerDatasource ( "mobilelocalfile" , MobileLocalFileDatasource ) ;