From db997955afb1fb339c2dac7426b3085ea80d63b1 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 6 Jun 2023 20:58:08 +0530 Subject: [PATCH] refactor(desktop): backup paths --- .../Domain/Service/BackupServiceInterface.ts | 2 +- .../src/Domain/Backups/BackupService.ts | 24 +++++++++++++------ packages/web/package.json | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/files/src/Domain/Service/BackupServiceInterface.ts b/packages/files/src/Domain/Service/BackupServiceInterface.ts index 18663ebdd..6ac148546 100644 --- a/packages/files/src/Domain/Service/BackupServiceInterface.ts +++ b/packages/files/src/Domain/Service/BackupServiceInterface.ts @@ -18,7 +18,7 @@ export interface BackupServiceInterface { getFilesBackupsLocation(): string | undefined openFilesBackupsLocation(): Promise openFileBackup(record: FileBackupRecord): Promise - getFileBackupAbsolutePath(record: FileBackupRecord): string + getFileBackupAbsolutePath(record: FileBackupRecord): Promise isTextBackupsEnabled(): boolean enableTextBackups(): Promise diff --git a/packages/services/src/Domain/Backups/BackupService.ts b/packages/services/src/Domain/Backups/BackupService.ts index 48a0c2296..13669e1ce 100644 --- a/packages/services/src/Domain/Backups/BackupService.ts +++ b/packages/services/src/Domain/Backups/BackupService.ts @@ -147,9 +147,10 @@ export class FilesBackupService extends AbstractService implements BackupService private async automaticallyEnableTextBackupsIfPreferenceNotSet(): Promise { if (this.storage.getValue(StorageKey.TextBackupsEnabled) == undefined) { this.storage.setValue(StorageKey.TextBackupsEnabled, true) - const location = `${await this.device.getUserDocumentsDirectory()}/${await this.prependWorkspacePathForPath( - TextBackupsDirectoryName, - )}` + const location = await this.device.joinPaths( + await this.device.getUserDocumentsDirectory(), + await this.prependWorkspacePathForPath(TextBackupsDirectoryName), + ) this.storage.setValue(StorageKey.TextBackupsLocation, location) } } @@ -378,13 +379,16 @@ export class FilesBackupService extends AbstractService implements BackupService return record } - public getFileBackupAbsolutePath(record: FileBackupRecord): string { + public getFileBackupAbsolutePath(record: FileBackupRecord): Promise { const location = this.getFilesBackupsLocation() - return `${location}/${record.relativePath}` + if (!location) { + throw new ClientDisplayableError('No files backups location set') + } + return this.device.joinPaths(location, record.relativePath) } public async openFileBackup(record: FileBackupRecord): Promise { - const location = this.getFileBackupAbsolutePath(record) + const location = await this.getFileBackupAbsolutePath(record) await this.device.openLocation(location) } @@ -459,7 +463,13 @@ export class FilesBackupService extends AbstractService implements BackupService return 'failed' } - const path = `${this.getFilesBackupsLocation()}/${fileBackup.relativePath}/${fileBackup.binaryFileName}` + const fileBackupsLocation = await this.getFilesBackupsLocation() + + if (!fileBackupsLocation) { + return 'failed' + } + + const path = await this.device.joinPaths(fileBackupsLocation, fileBackup.relativePath, fileBackup.binaryFileName) const token = await this.device.getFileBackupReadToken(path) let readMore = true diff --git a/packages/web/package.json b/packages/web/package.json index 933cdbbc8..0a4a6cede 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -3,7 +3,7 @@ "version": "3.161.0", "license": "AGPL-3.0-or-later", "main": "dist/app.js", - "author": "Standard Notes.", + "author": "Standard Notes", "private": true, "files": [ "dist"