Skip to content

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

fix(files): encode special characters not handled by AuthInterceptor

johavend9e81f02dc5f
diff --git a/backend/src/applications/files/modules/only-office/only-office-manager.service.ts b/backend/src/applications/files/modules/only-office/only-office-manager.service.ts
index daa56226..85699f1f 100644
--- a/backend/src/applications/files/modules/only-office/only-office-manager.service.ts
+++ b/backend/src/applications/files/modules/only-office/only-office-manager.service.ts
@@ -8,6 +8,7 @@ import os from 'node:os'
import path from 'node:path'
import { JwtIdentityPayload } from '../../../../authentication/interfaces/jwt-payload.interface'
import { convertHumanTimeToSeconds } from '../../../../common/functions'
+import { encodeUrl } from '../../../../common/shared'
import { configuration } from '../../../../configuration/config.environment'
import { Cache } from '../../../../infrastructure/cache/services/cache.service'
import { ContextManager } from '../../../../infrastructure/context/services/context-manager.service'
@@ -99,8 +100,8 @@ export class OnlyOfficeManager {
}
const isMobile: boolean = this.mobileRegex.test(req.headers['user-agent'])
const authToken: string = await this.genAuthToken(user)
- const fileUrl = this.buildUrl(API_ONLY_OFFICE_DOCUMENT, space.url, authToken)
- const callBackUrl = this.buildUrl(API_ONLY_OFFICE_CALLBACK, space.url, authToken)
+ const fileUrl = this.buildUrl(API_ONLY_OFFICE_DOCUMENT, encodeUrl(space.url), authToken)
+ const callBackUrl = this.buildUrl(API_ONLY_OFFICE_CALLBACK, encodeUrl(space.url), authToken)
const config: OnlyOfficeReqDto = await this.genConfiguration(user, space, mode, fileUrl, fileExtension, callBackUrl, isMobile, hasLock)
config.config.token = await this.genPayloadToken(config.config)
return config
diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
index e95c72ff..2b489a99 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
@@ -13,10 +13,10 @@
<app-files-viewer-image [currentHeight]="currentHeight" [(file)]="currentFile" [directoryImages]="directoryImages()"></app-files-viewer-image>
}
@case (SHORT_MIME.PDF) {
- <app-files-viewer-pdf [currentHeight]="currentHeight" [fileUrl]="currentFile.dataUrl"></app-files-viewer-pdf>
+ <app-files-viewer-pdf [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-pdf>
}
@case (SHORT_MIME.MEDIA) {
- <app-files-viewer-media [currentHeight]="currentHeight" [fileUrl]="currentFile.dataUrl"></app-files-viewer-media>
+ <app-files-viewer-media [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-media>
}
@case (SHORT_MIME.DOCUMENT) {
@if (editorProvider.collabora) {
diff --git a/frontend/src/app/applications/files/components/sidebar/files-selection.component.html b/frontend/src/app/applications/files/components/sidebar/files-selection.component.html
index feb2ee10..ef462807 100644
--- a/frontend/src/app/applications/files/components/sidebar/files-selection.component.html
+++ b/frontend/src/app/applications/files/components/sidebar/files-selection.component.html
@@ -31,7 +31,7 @@
</div>
}
@case ('media') {
- <app-files-viewer-media [currentHeight]="cardImageSize" [fileUrl]="f.dataUrl"></app-files-viewer-media>
+ <app-files-viewer-media [currentHeight]="cardImageSize" [file]="f"></app-files-viewer-media>
}
@default {
<img [src]="f.mimeUrl" alt="" [style.height.px]="cardImageSize" (error)="f.fallBackMimeUrl()">
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-media.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-media.component.ts
index 195f2049..d9e56341 100755
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-media.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-media.component.ts
@@ -3,6 +3,7 @@ import { VgBufferingModule } from '@videogular/ngx-videogular/buffering'
import { VgControlsModule } from '@videogular/ngx-videogular/controls'
import { VgCoreModule } from '@videogular/ngx-videogular/core'
import { VgOverlayPlayModule } from '@videogular/ngx-videogular/overlay-play'
+import { FileModel } from '../../models/file.model'
@Component({
selector: 'app-files-viewer-media',
@@ -11,12 +12,12 @@ import { VgOverlayPlayModule } from '@videogular/ngx-videogular/overlay-play'
template: `
<vg-player [style.height.px]="currentHeight()">
<video [vgMedia]="$any(media)" #media preload="none" autoplay controls>
- <source [src]="fileUrl()" type="video/webm" />
+ <source [src]="file().dataUrl" type="video/webm" />
</video>
</vg-player>
`
})
export class FilesViewerMediaComponent {
- fileUrl = input<string>()
+ file = input.required<FileModel>()
currentHeight = input<number>()
}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-pdf.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-pdf.component.ts
index b7aca886..02a923ba 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-pdf.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-pdf.component.ts
@@ -1,6 +1,7 @@
import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core'
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
import { assetsUrl } from '../../files.constants'
+import { FileModel } from '../../models/file.model'
@Component({
selector: 'app-files-viewer-pdf',
@@ -8,11 +9,11 @@ import { assetsUrl } from '../../files.constants'
template: ` <iframe [src]="url()" class="app-viewer-iframe" [style.height.px]="currentHeight()"></iframe> `
})
export class FilesViewerPdfComponent {
- fileUrl = input<string>()
+ file = input.required<FileModel>()
currentHeight = input<number>()
private readonly sanitizer = inject(DomSanitizer)
private readonly pdfjsUrl = `${assetsUrl}/pdfjs/web/viewer.html?file=`
url = computed<SafeResourceUrl | null>(() =>
- this.fileUrl() ? this.sanitizer.bypassSecurityTrustResourceUrl(`${this.pdfjsUrl}${encodeURIComponent(this.fileUrl())}`) : null
+ this.file() ? this.sanitizer.bypassSecurityTrustResourceUrl(`${this.pdfjsUrl}${this.file().dataUrl}`) : null
)
}
diff --git a/frontend/src/app/applications/files/models/file.model.ts b/frontend/src/app/applications/files/models/file.model.ts
index a09b550b..33efa03a 100644
--- a/frontend/src/app/applications/files/models/file.model.ts
+++ b/frontend/src/app/applications/files/models/file.model.ts
@@ -9,7 +9,7 @@ import type { FileEditorProviders } from '@sync-in-server/backend/src/applicatio
import { ONLY_OFFICE_EXTENSIONS } from '@sync-in-server/backend/src/applications/files/modules/only-office/only-office.constants'
import type { File } from '@sync-in-server/backend/src/applications/files/schemas/file.interface'
import { SPACE_OPERATION } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
-import { currentTimeStamp, popFromObject } from '@sync-in-server/backend/src/common/shared'
+import { currentTimeStamp, encodeUrl, popFromObject } from '@sync-in-server/backend/src/common/shared'
import type { Observable } from 'rxjs'
import { convertBytesToText, getNewly } from '../../../common/utils/functions'
import { dJs } from '../../../common/utils/time'
@@ -97,16 +97,20 @@ export class FileModel implements File {
this.updateNbBadges()
}
+ get encodedPath(): string {
+ return encodeUrl(this.path)
+ }
+
get dataUrl(): string {
- return `${API_FILES_OPERATION}/${this.path}`
+ return `${API_FILES_OPERATION}/${this.encodedPath}`
}
get taskUrl(): string {
- return `${API_FILES_TASK_OPERATION}/${this.path}`
+ return `${API_FILES_TASK_OPERATION}/${this.encodedPath}`
}
get thumbnailUrl(): string {
- return `${API_FILES_OPERATION_THUMBNAIL}/${this.path}`
+ return `${API_FILES_OPERATION_THUMBNAIL}/${this.encodedPath}`
}
fallBackMimeUrl() {
@@ -142,6 +146,17 @@ export class FileModel implements File {
return dot >= 0 ? this.name.slice(dot + 1).toLowerCase() : ''
}
+ updateNbBadges() {
+ this.galleryBadges = []
+ if (this.lock) this.galleryBadges.push('lock')
+ if (this.shares.length) this.galleryBadges.push('shares')
+ if (this.spaces.length) this.galleryBadges.push('spaces')
+ if (this.links.length) this.galleryBadges.push('links')
+ if (this.syncs.length) this.galleryBadges.push('syncs')
+ if (this.hasComments) this.galleryBadges.push('comments')
+ this.nbBadges = this.galleryBadges.length
+ }
+
private getType(inShare: boolean): 'directory_share' | 'directory' | 'file' {
return this.isDir ? (inShare ? mimeDirectoryShare : mimeDirectory) : mimeFile
}
@@ -250,15 +265,4 @@ export class FileModel implements File {
this.updateNbBadges()
}
}
-
- updateNbBadges() {
- this.galleryBadges = []
- if (this.lock) this.galleryBadges.push('lock')
- if (this.shares.length) this.galleryBadges.push('shares')
- if (this.spaces.length) this.galleryBadges.push('spaces')
- if (this.links.length) this.galleryBadges.push('links')
- if (this.syncs.length) this.galleryBadges.push('syncs')
- if (this.hasComments) this.galleryBadges.push('comments')
- this.nbBadges = this.galleryBadges.length
- }
}