refactor: import/export use cases (#2397)
This commit is contained in:
@@ -103,15 +103,15 @@ export class DesktopManager
|
||||
|
||||
private async getBackupFile(): Promise<string | undefined> {
|
||||
const encrypted = this.application.hasProtectionSources()
|
||||
const data = encrypted
|
||||
? await this.application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
: await this.application.createDecryptedBackupFile()
|
||||
const result = encrypted
|
||||
? await this.application.createEncryptedBackupFile.execute({ skipAuthorization: true })
|
||||
: await this.application.createDecryptedBackupFile.execute()
|
||||
|
||||
if (data) {
|
||||
return JSON.stringify(data, null, 2)
|
||||
if (result.isFailed()) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return undefined
|
||||
return JSON.stringify(result.getValue(), null, 2)
|
||||
}
|
||||
|
||||
getExtServerHost(): string {
|
||||
|
||||
@@ -58,14 +58,16 @@ const DataBackups = ({ application }: Props) => {
|
||||
}, [refreshEncryptionStatus])
|
||||
|
||||
const downloadDataArchive = async () => {
|
||||
const data = isBackupEncrypted
|
||||
? await application.createEncryptedBackupFile()
|
||||
: await application.createDecryptedBackupFile()
|
||||
const result = isBackupEncrypted
|
||||
? await application.createEncryptedBackupFile.execute()
|
||||
: await application.createDecryptedBackupFile.execute()
|
||||
|
||||
if (!data) {
|
||||
if (result.isFailed()) {
|
||||
return
|
||||
}
|
||||
|
||||
const data = result.getValue()
|
||||
|
||||
const blobData = new Blob([JSON.stringify(data, null, 2)], {
|
||||
type: 'text/json',
|
||||
})
|
||||
@@ -126,15 +128,11 @@ const DataBackups = ({ application }: Props) => {
|
||||
|
||||
setIsImportDataLoading(false)
|
||||
|
||||
if (!result) {
|
||||
return
|
||||
}
|
||||
|
||||
let statusText = STRING_IMPORT_SUCCESS
|
||||
if ('error' in result) {
|
||||
statusText = result.error.text
|
||||
} else if (result.errorCount) {
|
||||
statusText = StringImportError(result.errorCount)
|
||||
if (result.isFailed()) {
|
||||
statusText = result.getError()
|
||||
} else if (result.getValue().errorCount) {
|
||||
statusText = StringImportError(result.getValue().errorCount)
|
||||
}
|
||||
void alertDialog({
|
||||
text: statusText,
|
||||
|
||||
Reference in New Issue
Block a user