refactor: import/export use cases (#2397)

This commit is contained in:
Mo
2023-08-10 08:08:17 -05:00
committed by GitHub
parent 5bb749b601
commit 1e965caf18
43 changed files with 1085 additions and 673 deletions

View File

@@ -20,8 +20,8 @@ import {
ApplicationStageChangedEventPayload,
StorageValueModes,
ChallengeObserver,
ImportDataReturnType,
ImportDataUseCase,
ImportDataResult,
ImportData,
StoragePersistencePolicies,
HomeServerServiceInterface,
DeviceInterface,
@@ -79,6 +79,8 @@ import {
SetHost,
MfaServiceInterface,
GenerateUuid,
CreateDecryptedBackupFile,
CreateEncryptedBackupFile,
} from '@standardnotes/services'
import {
SNNote,
@@ -133,6 +135,7 @@ import { GetAuthenticatorAuthenticationOptions } from '@Lib/Domain/UseCase/GetAu
import { Dependencies } from './Dependencies/Dependencies'
import { TYPES } from './Dependencies/Types'
import { RegisterApplicationServicesEvents } from './Dependencies/DependencyEvents'
import { Result } from '@standardnotes/domain-core'
/** How often to automatically sync, in milliseconds */
const DEFAULT_AUTO_SYNC_INTERVAL = 30_000
@@ -672,26 +675,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
return this.protections.authorizeAutolockIntervalChange()
}
public async createEncryptedBackupFileForAutomatedDesktopBackups(): Promise<BackupFile | undefined> {
return this.encryption.createEncryptedBackupFile()
}
public async createEncryptedBackupFile(): Promise<BackupFile | undefined> {
if (!(await this.protections.authorizeBackupCreation())) {
return
}
return this.encryption.createEncryptedBackupFile()
}
public async createDecryptedBackupFile(): Promise<BackupFile | undefined> {
if (!(await this.protections.authorizeBackupCreation())) {
return
}
return this.encryption.createDecryptedBackupFile()
}
public isEphemeralSession(): boolean {
return this.storage.isEphemeralSession()
}
@@ -842,8 +825,8 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
})
}
public async importData(data: BackupFile, awaitSync = false): Promise<ImportDataReturnType> {
const usecase = this.dependencies.get<ImportDataUseCase>(TYPES.ImportDataUseCase)
public async importData(data: BackupFile, awaitSync = false): Promise<Result<ImportDataResult>> {
const usecase = this.dependencies.get<ImportData>(TYPES.ImportData)
return usecase.execute(data, awaitSync)
}
@@ -1164,6 +1147,14 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
return this.dependencies.get<GenerateUuid>(TYPES.GenerateUuid)
}
public get createDecryptedBackupFile(): CreateDecryptedBackupFile {
return this.dependencies.get<CreateDecryptedBackupFile>(TYPES.CreateDecryptedBackupFile)
}
public get createEncryptedBackupFile(): CreateEncryptedBackupFile {
return this.dependencies.get<CreateEncryptedBackupFile>(TYPES.CreateEncryptedBackupFile)
}
private get migrations(): MigrationService {
return this.dependencies.get<MigrationService>(TYPES.MigrationService)
}