Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(frontend:files): refresh MIME metadata after move

johavenbb85795bd3c5
diff --git a/backend/src/applications/files/files.controller.ts b/backend/src/applications/files/files.controller.ts
index 84188534..72ec125a 100644
--- a/backend/src/applications/files/files.controller.ts
+++ b/backend/src/applications/files/files.controller.ts
@@ -49,6 +49,7 @@ import { UserHaveRole } from '../users/decorators/roles.decorator'
import { USER_ROLE } from '../users/constants/user'
import { UserRolesGuard } from '../users/guards/roles.guard'
import { IndexingStatus } from './interfaces/indexing.interface'
+import type { CopyMoveFileResponse } from './interfaces/copy-move-file.interface'
@Controller(FILES_ROUTE.BASE)
@UseGuards(SpaceGuard)
@@ -96,26 +97,12 @@ export class FilesController {
}
@Copy(`${FILES_ROUTE.OPERATION}/*`)
- async copy(
- @GetUser() user: UserModel,
- @GetSpace() space: SpaceEnv,
- @Body() copyMoveFileDto: CopyMoveFileDto
- ): Promise<{
- path: string
- name: string
- }> {
+ async copy(@GetUser() user: UserModel, @GetSpace() space: SpaceEnv, @Body() copyMoveFileDto: CopyMoveFileDto): Promise<CopyMoveFileResponse> {
return this.filesMethods.copy(user, space, copyMoveFileDto)
}
@Move(`${FILES_ROUTE.OPERATION}/*`)
- async move(
- @GetUser() user: UserModel,
- @GetSpace() space: SpaceEnv,
- @Body() copyMoveFileDto: CopyMoveFileDto
- ): Promise<{
- path: string
- name: string
- }> {
+ async move(@GetUser() user: UserModel, @GetSpace() space: SpaceEnv, @Body() copyMoveFileDto: CopyMoveFileDto): Promise<CopyMoveFileResponse> {
return this.filesMethods.move(user, space, copyMoveFileDto)
}
diff --git a/backend/src/applications/files/interfaces/copy-move-file.interface.ts b/backend/src/applications/files/interfaces/copy-move-file.interface.ts
new file mode 100644
index 00000000..9f4bdda3
--- /dev/null
+++ b/backend/src/applications/files/interfaces/copy-move-file.interface.ts
@@ -0,0 +1,5 @@
+export interface CopyMoveFileResponse {
+ path: string
+ name: string
+ mime: string
+}
diff --git a/backend/src/applications/files/services/files-methods.service.ts b/backend/src/applications/files/services/files-methods.service.ts
index c4b4e512..3bff53fc 100644
--- a/backend/src/applications/files/services/files-methods.service.ts
+++ b/backend/src/applications/files/services/files-methods.service.ts
@@ -11,9 +11,10 @@ import { CompressFileDto, CopyMoveFileDto, DownloadFileDto, MakeFileDto } from '
import { FileLockProps } from '../interfaces/file-props.interface'
import { FileError } from '../models/file-error'
import { LockConflict } from '../models/file-lock-error'
-import { checkFileName, dirName, fileName, isPathExists, sanitizeName } from '../utils/files'
+import { checkFileName, dirName, fileName, getMimeType, isPathExists, isPathIsDir, sanitizeName } from '../utils/files'
import { SendFile } from '../utils/send-file'
import { FilesManager } from './files-manager.service'
+import type { CopyMoveFileResponse } from '../interfaces/copy-move-file.interface'
@Injectable()
export class FilesMethods {
@@ -54,25 +55,11 @@ export class FilesMethods {
}
}
- copy(
- user: UserModel,
- space: SpaceEnv,
- copyMoveFileDto: CopyMoveFileDto
- ): Promise<{
- path: string
- name: string
- }> {
+ copy(user: UserModel, space: SpaceEnv, copyMoveFileDto: CopyMoveFileDto): Promise<CopyMoveFileResponse> {
return this.copyMove(user, space, copyMoveFileDto, false)
}
- move(
- user: UserModel,
- space: SpaceEnv,
- copyMoveFileDto: CopyMoveFileDto
- ): Promise<{
- path: string
- name: string
- }> {
+ move(user: UserModel, space: SpaceEnv, copyMoveFileDto: CopyMoveFileDto): Promise<CopyMoveFileResponse> {
return this.copyMove(user, space, copyMoveFileDto, true)
}
@@ -179,27 +166,19 @@ export class FilesMethods {
}
}
- private async copyMove(
- user: UserModel,
- space: SpaceEnv,
- copyMoveFileDto: CopyMoveFileDto,
- isMove: boolean
- ): Promise<{
- path: string
- name: string
- }> {
+ private async copyMove(user: UserModel, space: SpaceEnv, copyMoveFileDto: CopyMoveFileDto, isMove: boolean): Promise<CopyMoveFileResponse> {
const dstUrl = path.join(copyMoveFileDto.dstDirectory, copyMoveFileDto.dstName ? copyMoveFileDto.dstName : fileName(space.realPath))
let dstSpace: SpaceEnv
try {
dstSpace = await this.spacesManager.spaceEnv(user, dstUrl.split('/'))
await this.filesManager.copyMove(user, space, dstSpace, isMove, copyMoveFileDto.overwrite)
+ return { path: dirName(dstUrl), name: fileName(dstUrl), mime: getMimeType(dstSpace.realPath, await isPathIsDir(dstSpace.realPath)) }
} catch (e) {
this.handleError(space, isMove ? FILE_OPERATION.MOVE : FILE_OPERATION.COPY, e, dstSpace)
}
- return { path: dirName(dstUrl), name: fileName(dstUrl) }
}
- private handleError(space: SpaceEnv, action: string, e: any, dstSpace?: SpaceEnv) {
+ private handleError(space: SpaceEnv, action: string, e: any, dstSpace?: SpaceEnv): never {
this.logger.error({ tag: this.handleError.name, msg: `unable to ${action} ${space.url}${dstSpace?.url ? ` -> ${dstSpace.url}` : ''} : ${e}` })
// Remove the last part to avoid exposing the path
const errorMsg = e.message.split(',')[0]
diff --git a/frontend/src/app/applications/files/models/file.model.ts b/frontend/src/app/applications/files/models/file.model.ts
index 65878e2d..3610f3fc 100644
--- a/frontend/src/app/applications/files/models/file.model.ts
+++ b/frontend/src/app/applications/files/models/file.model.ts
@@ -123,8 +123,9 @@ export class FileModel implements File {
this.path = [...this.path.split('/').slice(0, -1), this.name].join('/')
}
- updateMime(mime: string) {
- this.mime = mime
+ updateMime(mime: string, inShare: boolean, editorConfig: FileEditorProviders) {
+ this.resetMimeState()
+ this.mime = this.getMime(mime, inShare, editorConfig)
this.setMimeUrl()
}
@@ -246,6 +247,16 @@ export class FileModel implements File {
return mime
}
+ private resetMimeState() {
+ this.shortMime = undefined
+ this.isImage = false
+ this.isViewable = false
+ this.isEditable = false
+ this.isTextProbeRequired = false
+ this.isCompressible = true
+ this.haveThumbnail = false
+ }
+
private setMimeUrl() {
this.mimeUrl = getAssetsMimeUrl(this.mime)
}
diff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.ts
index 1caac9aa..1f0b500b 100644
--- a/frontend/src/app/applications/files/services/files.service.ts
+++ b/frontend/src/app/applications/files/services/files.service.ts
@@ -25,6 +25,7 @@ import type {
MakeFileDto,
SearchFilesDto
} from '@sync-in-server/backend/src/applications/files/dto/file-operations.dto'
+import type { CopyMoveFileResponse } from '@sync-in-server/backend/src/applications/files/interfaces/copy-move-file.interface'
import type { FileLockProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'
import type { FileTree } from '@sync-in-server/backend/src/applications/files/interfaces/file-tree.interface'
import type { FileTask } from '@sync-in-server/backend/src/applications/files/models/file-task'
@@ -138,11 +139,11 @@ export class FilesService {
}
}
- rename(file: FileModel, name: string, overwrite = false): Observable<Pick<FileTask, 'name'>> {
+ rename(file: FileModel, name: string, overwrite = false): Observable<CopyMoveFileResponse> {
if (!this.isValidName(name)) return EMPTY
const dstDirectory = file.path.split('/').slice(0, -1).join('/') || '.'
const op: CopyMoveFileDto = { dstDirectory: dstDirectory, dstName: name, overwrite: overwrite }
- return this.http.request<Pick<FileTask, 'name'>>(FILE_OPERATION.MOVE, file.dataUrl, { body: op })
+ return this.http.request<CopyMoveFileResponse>(FILE_OPERATION.MOVE, file.dataUrl, { body: op })
}
delete(files: FileModel[]) {
diff --git a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
index 5175bb75..a92bd02a 100644
--- a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
+++ b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
@@ -34,9 +34,10 @@ import { ContextMenuComponent, ContextMenuModule } from '@perfectmemory/ngx-cont
import { TAR_EXTENSION } from '@sync-in-server/backend/src/applications/files/constants/compress'
import { FILE_OPERATION } from '@sync-in-server/backend/src/applications/files/constants/operations'
import type { CompressFileDto } from '@sync-in-server/backend/src/applications/files/dto/file-operations.dto'
+import type { CopyMoveFileResponse } from '@sync-in-server/backend/src/applications/files/interfaces/copy-move-file.interface'
import type { FileProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'
import type { FileSpace } from '@sync-in-server/backend/src/applications/files/interfaces/file-space.interface'
-import { type FileTask, FileTaskStatus } from '@sync-in-server/backend/src/applications/files/models/file-task'
+import { FileTaskStatus } from '@sync-in-server/backend/src/applications/files/models/file-task'
import { SHARE_TYPE } from '@sync-in-server/backend/src/applications/shares/constants/shares'
import { SPACE_OPERATION, SPACE_REPOSITORY } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
import type { SpaceFiles } from '@sync-in-server/backend/src/applications/spaces/interfaces/space-files.interface'
@@ -484,11 +485,10 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
.rename(f, renamedTo, overwrite)
.pipe(take(1))
.subscribe({
- next: (dto: Pick<FileTask, 'name'>) => {
+ next: (dto: CopyMoveFileResponse) => {
f.rename(dto.name)
- f.isEditable = false
+ f.updateMime(dto.mime, this.isSharesRepo, this.store.server().files.editors)
if (overwrite) {
- f.updateMime(fileExists.mime)
this.sortBy(
this.sortTable.sortParam.column,
false,