diff --git a/src/apps/fuse/callbacks/UploadOnRename.ts b/src/apps/fuse/callbacks/UploadOnRename.ts index 5260153aa..b19d8bafa 100644 --- a/src/apps/fuse/callbacks/UploadOnRename.ts +++ b/src/apps/fuse/callbacks/UploadOnRename.ts @@ -72,7 +72,11 @@ export class UploadOnRename { await this.offline.offlineContentsUploader.run( offlineFile.id, offlineFile.path, - fileToOverride.contentsId + { + contentsId: fileToOverride.contentsId, + name: fileToOverride.name, + extension: fileToOverride.type, + } ); return right(UploadOnRename.SUCCESS); diff --git a/src/context/offline-drive/contents/application/OfflineContentsUploader.ts b/src/context/offline-drive/contents/application/OfflineContentsUploader.ts index dbf4cb898..1d8f39bab 100644 --- a/src/context/offline-drive/contents/application/OfflineContentsUploader.ts +++ b/src/context/offline-drive/contents/application/OfflineContentsUploader.ts @@ -6,6 +6,12 @@ import { FilePath } from '../../../virtual-drive/files/domain/FilePath'; import { OfflineContentsName } from '../domain/OfflineContentsName'; import Logger from 'electron-log'; +interface Replaces { + contentsId: string; + name: string; + extension: string; +} + export class OfflineContentsUploader { constructor( private readonly repository: OfflineContentsRepository, @@ -16,7 +22,7 @@ export class OfflineContentsUploader { async run( name: OfflineContentsName, path: FilePath, - replaces?: string + replaces?: Replaces ): Promise { const { contents, stream, abortSignal } = await this.repository.createStream(name); @@ -25,8 +31,8 @@ export class OfflineContentsUploader { stream, contents, { - name: path.name(), - extension: path.extension(), + name: replaces?.name || path.name(), + extension: replaces?.extension || path.extension(), }, abortSignal ); @@ -40,7 +46,7 @@ export class OfflineContentsUploader { offlineContentsPath: contents.absolutePath, size: contents.size, path: path.value, - replaces, + replaces: replaces?.contentsId, }); await this.eventBus.publish([contentsUploadedEvent]); diff --git a/src/context/offline-drive/contents/infrastructure/NodeFSOfflineContentsRepository.ts b/src/context/offline-drive/contents/infrastructure/NodeFSOfflineContentsRepository.ts index ec74e651a..80a291559 100644 --- a/src/context/offline-drive/contents/infrastructure/NodeFSOfflineContentsRepository.ts +++ b/src/context/offline-drive/contents/infrastructure/NodeFSOfflineContentsRepository.ts @@ -1,11 +1,11 @@ -import fs, { closeSync, createReadStream, readSync, unlink, watch } from 'fs'; +import fs, { createReadStream, unlink, watch } from 'fs'; import { readFile, stat as statPromises } from 'fs/promises'; import { OfflineContentsRepository } from '../domain/OfflineContentsRepository'; import { OfflineFile } from '../../files/domain/OfflineFile'; import { LocalFileContentsDirectoryProvider } from '../../../virtual-drive/shared/domain/LocalFileContentsDirectoryProvider'; import { basename, dirname, join } from 'path'; import Logger from 'electron-log'; -import { Readable, Stream } from 'stream'; +import { Readable } from 'stream'; import { OfflineContents } from '../domain/OfflineContents'; import { OfflineContentsName } from '../domain/OfflineContentsName'; import { OfflineFileId } from '../../files/domain/OfflineFileId';