Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
feat(editors): support dynamic UI theme for OnlyOffice and Collabora
johaven18e49f98662f
diff --git a/backend/src/applications/files/editors/only-office/only-office-manager.service.ts b/backend/src/applications/files/editors/only-office/only-office-manager.service.tsindex 1dc3253d..f3cdc988 100644--- a/backend/src/applications/files/editors/only-office/only-office-manager.service.ts+++ b/backend/src/applications/files/editors/only-office/only-office-manager.service.ts@@ -75,7 +75,7 @@ export class OnlyOfficeManager {private readonly filesLockManager: FilesLockManager) {}- async getSettings(user: UserModel, space: SpaceEnv, req: FastifySpaceRequest): Promise<OnlyOfficeReqDto> {+ async getSettings(user: UserModel, space: SpaceEnv, req: FastifySpaceRequest, theme?: 'dark' | 'light'): Promise<OnlyOfficeReqDto> {if (!(await isPathExists(space.realPath))) {throw new HttpException('Document not found', HttpStatus.BAD_REQUEST)}@@ -111,6 +111,7 @@ export class OnlyOfficeManager {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.editorConfig.customization.uiTheme = `theme-${theme ?? 'light'}`config.config.token = await this.genPayloadToken(config.config)return config}diff --git a/backend/src/applications/files/editors/only-office/only-office.controller.spec.ts b/backend/src/applications/files/editors/only-office/only-office.controller.spec.tsindex e74c52bc..004d1c03 100644--- a/backend/src/applications/files/editors/only-office/only-office.controller.spec.ts+++ b/backend/src/applications/files/editors/only-office/only-office.controller.spec.ts@@ -64,7 +64,7 @@ describe(OnlyOfficeController.name, () => {const result = await controller.onlyOfficeSettings(req)expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledTimes(1)- expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, req)+ expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, req, undefined)expect(result).toBe(expected)})@@ -77,7 +77,7 @@ describe(OnlyOfficeController.name, () => {const result = await controller.onlyOfficeSettings(req)- expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, req)+ expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, req, undefined)expect(result).toBe(expected)})})diff --git a/backend/src/applications/files/editors/only-office/only-office.controller.ts b/backend/src/applications/files/editors/only-office/only-office.controller.tsindex 3227e8da..07c485e8 100644--- a/backend/src/applications/files/editors/only-office/only-office.controller.ts+++ b/backend/src/applications/files/editors/only-office/only-office.controller.ts@@ -1,4 +1,4 @@-import { Body, Controller, Get, HttpCode, HttpStatus, Post, Request, Res, StreamableFile, UseGuards, UseInterceptors } from '@nestjs/common'+import { Body, Controller, Get, HttpCode, HttpStatus, Post, Query, Request, Res, StreamableFile, UseGuards, UseInterceptors } from '@nestjs/common'import { FastifyReply } from 'fastify'import { ContextInterceptor } from '../../../../infrastructure/context/interceptors/context.interceptor'import { SPACE_OPERATION } from '../../../spaces/constants/spaces'@@ -25,8 +25,8 @@ export class OnlyOfficeController {@Get(`${ONLY_OFFICE_ROUTE.SETTINGS}/*`)@UseGuards(SpaceGuard)@UseInterceptors(ContextInterceptor)- onlyOfficeSettings(@Request() req: FastifySpaceRequest): Promise<OnlyOfficeReqDto> {- return this.filesOnlyOfficeManager.getSettings(req.user, req.space, req)+ onlyOfficeSettings(@Request() req: FastifySpaceRequest, @Query('theme') theme?: 'light' | 'dark'): Promise<OnlyOfficeReqDto> {+ return this.filesOnlyOfficeManager.getSettings(req.user, req.space, req, theme)}@Get(`${ONLY_OFFICE_ROUTE.DOCUMENT}/*`)diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.tsindex 925ed9d0..41c1bc03 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.ts@@ -1,10 +1,10 @@import { HttpClient, HttpErrorResponse } from '@angular/common/http'-import { Component, inject, input, model, OnDestroy, OnInit } from '@angular/core'-import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'+import { Component, ElementRef, inject, input, model, OnDestroy, OnInit, ViewChild } from '@angular/core'import { FILE_MODE } from '@sync-in-server/backend/src/applications/files/constants/operations'import { COLLABORA_APP_LOCK } from '@sync-in-server/backend/src/applications/files/editors/collabora-online/collabora-online.constants'import type { CollaboraOnlineReqDto } from '@sync-in-server/backend/src/applications/files/editors/collabora-online/collabora-online.dtos'import { API_COLLABORA_ONLINE_SETTINGS } from '@sync-in-server/backend/src/applications/files/editors/collabora-online/collabora-online.routes'+import { themeDark } from '../../../../layout/layout.interfaces'import { LayoutService } from '../../../../layout/layout.service'import { StoreService } from '../../../../store/store.service'import { FileModel } from '../../models/file.model'@@ -16,11 +16,10 @@ import { fileLockPropsToString } from '../utils/file-lock.utils'template: `@if (documentServerUrl) {<div class="app-collabora-online-border" [style.height.px]="currentHeight()">- <iframe- [src]="documentServerUrl"- class="app-viewer-iframe collabora-scaling"- allow="clipboard-read *; clipboard-write *; fullscreen"- ></iframe>+ <iframe [attr.name]="frameName" class="app-viewer-iframe collabora-scaling" allow="clipboard-read *; clipboard-write *; fullscreen"></iframe>+ <form #documentForm [action]="documentServerUrl" method="post" [attr.target]="frameName" hidden>+ <input type="hidden" name="ui_defaults" [value]="collaboraUiDefaults" />+ </form></div>}`,@@ -39,15 +38,22 @@ export class FilesViewerCollaboraOnlineComponent implements OnInit, OnDestroy {file = input.required<FileModel>()isReadonly = model.required<boolean>()currentHeight = input<number>()- protected documentServerUrl: SafeResourceUrl = null+ protected documentServerUrl: string = null+ protected frameName: string+ protected collaboraUiDefaults: stringprivate readonly http = inject(HttpClient)private readonly filesService = inject(FilesService)private readonly layout = inject(LayoutService)private readonly store = inject(StoreService)- private readonly sanitizer = inject(DomSanitizer)private shouldReconcileMetadata = false+ @ViewChild('documentForm')+ private set documentForm(form: ElementRef<HTMLFormElement> | undefined) {+ form?.nativeElement.submit()+ }+ngOnInit() {+ this.frameName = `collabora-frame-${this.file().id}`this.http.get<CollaboraOnlineReqDto>(`${API_COLLABORA_ONLINE_SETTINGS}/${this.file().path}`).subscribe({next: (data) => {if (!data) {@@ -77,7 +83,10 @@ export class FilesViewerCollaboraOnlineComponent implements OnInit, OnDestroy {isExclusive: false})}- this.documentServerUrl = this.sanitizer.bypassSecurityTrustResourceUrl(`${data.documentServerUrl}&lang=${this.layout.getCurrentLanguage()}`)+ const documentServerUrl = new URL(data.documentServerUrl)+ documentServerUrl.searchParams.set('lang', this.layout.getCurrentLanguage())+ this.collaboraUiDefaults = `UITheme=${this.layout.switchTheme.getValue() === themeDark ? 'dark' : 'light'};`+ this.documentServerUrl = documentServerUrl.toString()},error: (e: HttpErrorResponse) => {this.layout.closeDialog()diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.tsindex af91e819..1bfa34b8 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts@@ -4,6 +4,7 @@ import { FILE_MODE } from '@sync-in-server/backend/src/applications/files/constaimport { EURO_OFFICE_APP_LOCK, ONLY_OFFICE_APP_LOCK } from '@sync-in-server/backend/src/applications/files/editors/only-office/only-office.constants'import type { OnlyOfficeReqDto } from '@sync-in-server/backend/src/applications/files/editors/only-office/only-office.dtos'import { API_ONLY_OFFICE_SETTINGS } from '@sync-in-server/backend/src/applications/files/editors/only-office/only-office.routes'+import { themeDark } from '../../../../layout/layout.interfaces'import { LayoutService } from '../../../../layout/layout.service'import { StoreService } from '../../../../store/store.service'import { FileModel } from '../../models/file.model'@@ -51,7 +52,8 @@ export class FilesViewerOnlyOfficeComponent implements OnInit, OnDestroy {ngOnInit() {this.docId = `viewer-doc-${this.file().id}`- this.http.get<OnlyOfficeReqDto>(`${API_ONLY_OFFICE_SETTINGS}/${this.file().path}`).subscribe({+ const theme = this.layout.switchTheme.getValue() === themeDark ? 'dark' : 'light'+ this.http.get<OnlyOfficeReqDto>(`${API_ONLY_OFFICE_SETTINGS}/${this.file().path}`, { params: { theme } }).subscribe({next: (data) => {if (!data) {this.layout.closeDialog()