Skip to content

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

feat(files): add Draw.io diagram editing support

johaven837132b07199
diff --git a/backend/src/app.bootstrap.ts b/backend/src/app.bootstrap.ts
index 0592bec1..b4a305e3 100644
--- a/backend/src/app.bootstrap.ts
+++ b/backend/src/app.bootstrap.ts
@@ -69,7 +69,8 @@ export async function appBootstrap(): Promise<NestFastifyApplication> {
? configuration.applications.files.editors.onlyoffice
: configuration.applications.files.editors.eurooffice
).externalServer,
- configuration.applications.files.editors.collabora.externalServer
+ configuration.applications.files.editors.collabora.externalServer,
+ configuration.applications.files.editors.drawio.externalServer
)
})
diff --git a/backend/src/app.constants.ts b/backend/src/app.constants.ts
index a0af6789..7cade2fb 100644
--- a/backend/src/app.constants.ts
+++ b/backend/src/app.constants.ts
@@ -2,14 +2,20 @@ import { loadVersion } from './app.functions'
export const VERSION = loadVersion()
export const USER_AGENT = `sync-in-server/${VERSION}`
-export const CONTENT_SECURITY_POLICY = (xOfficeServer: string, collaboraServer: string) => ({
+export const CONTENT_SECURITY_POLICY = (xOfficeServer: string, collaboraServer: string, drawioServer: string) => ({
useDefaults: false,
directives: {
- defaultSrc: ["'self'", xOfficeServer || '', collaboraServer || ''],
+ defaultSrc: ["'self'"],
+ baseUri: ["'self'"],
+ objectSrc: ["'none'"],
+ // Angular's production CSS loader uses an inline script and an inline load handler.
scriptSrc: ["'self'", "'unsafe-inline'", "'wasm-unsafe-eval'", xOfficeServer || ''],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'", 'data:'],
- fontSrc: ["'self'"]
+ fontSrc: ["'self'"],
+ frameSrc: ["'self'", 'blob:', xOfficeServer || '', collaboraServer || '', drawioServer || ''],
+ frameAncestors: ["'self'"],
+ formAction: ["'self'", collaboraServer || '']
}
})
diff --git a/backend/src/applications/files/assets/samples/sample.drawio b/backend/src/applications/files/assets/samples/sample.drawio
new file mode 100644
index 00000000..7fde37dc
--- /dev/null
+++ b/backend/src/applications/files/assets/samples/sample.drawio
@@ -0,0 +1 @@
+<mxfile><diagram name="Page-1"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>
diff --git a/backend/src/applications/files/constants/files.ts b/backend/src/applications/files/constants/files.ts
index 8fc74fd8..177e2b99 100644
--- a/backend/src/applications/files/constants/files.ts
+++ b/backend/src/applications/files/constants/files.ts
@@ -8,6 +8,8 @@ export const TEMPORARY_PATH = {
ACTORS: 'users'
} as const
export const EXTRA_MIMES_TYPE = new Map([
+ ['.drawio', 'application-x-drawio'],
+ ['.dwb', 'application-x-drawio-wb'],
['.go', 'text-x-go'],
['.gz', 'application-gzip'],
['.gzip', 'application-gzip'],
diff --git a/backend/src/applications/files/constants/samples.ts b/backend/src/applications/files/constants/samples.ts
index c9b13cb8..c9c244a7 100644
--- a/backend/src/applications/files/constants/samples.ts
+++ b/backend/src/applications/files/constants/samples.ts
@@ -1,5 +1,5 @@
export const SAMPLE_PATH_WITHOUT_EXT = '../assets/samples/sample'
-export const SAMPLE_DOCUMENT_GROUPS = ['opendocument', 'microsoft'] as const
+export const SAMPLE_DOCUMENT_GROUPS = ['opendocument', 'microsoft', 'drawio'] as const
export type SampleDocumentGroup = (typeof SAMPLE_DOCUMENT_GROUPS)[number]
export type DocumentTypes = Record<string, string>
@@ -13,9 +13,16 @@ export const DOCUMENT_TYPES_BY_GROUP: Record<SampleDocumentGroup, DocumentTypes>
'Microsoft Word': 'docx',
'Microsoft Excel': 'xlsx',
'Microsoft PowerPoint': 'pptx'
+ },
+ drawio: {
+ Diagram: 'drawio'
}
}
+export const SAMPLE_DOCUMENT_EXTENSIONS = new Set<string>(
+ Object.values(DOCUMENT_TYPES_BY_GROUP).flatMap((documentTypes) => Object.values(documentTypes))
+)
+
export const DEFAULT_DOCUMENT_TYPES: DocumentTypes = {
Text: 'txt',
Markdown: 'md'
diff --git a/backend/src/applications/files/editors/drawio/drawio-manager.service.spec.ts b/backend/src/applications/files/editors/drawio/drawio-manager.service.spec.ts
new file mode 100644
index 00000000..8a32c2f2
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio-manager.service.spec.ts
@@ -0,0 +1,101 @@
+import { HttpException, HttpStatus } from '@nestjs/common'
+import { Test, TestingModule } from '@nestjs/testing'
+import { configuration } from '../../../../configuration/config.environment'
+import { ContextManager } from '../../../../infrastructure/context/services/context-manager.service'
+import type { SpaceEnv } from '../../../spaces/models/space-env.model'
+import * as filesUtils from '../../utils/files'
+import { DrawioManager } from './drawio-manager.service'
+
+vi.mock('../../utils/files')
+
+describe(DrawioManager.name, () => {
+ let service: DrawioManager
+ let contextManager: ContextManager
+ let previousExternalServer: string
+
+ const mockSpace = {
+ realPath: '/path/to/diagram.drawio'
+ } as SpaceEnv
+
+ beforeEach(async () => {
+ previousExternalServer = configuration.applications.files.editors.drawio.externalServer
+ configuration.applications.files.editors.drawio.externalServer = null
+ const module: TestingModule = await Test.createTestingModule({
+ providers: [
+ DrawioManager,
+ {
+ provide: ContextManager,
+ useValue: {
+ publicOriginUrl: vi.fn().mockReturnValue('https://sync-in.test')
+ }
+ }
+ ]
+ }).compile()
+
+ module.useLogger(['fatal'])
+ service = module.get<DrawioManager>(DrawioManager)
+ contextManager = module.get<ContextManager>(ContextManager)
+ vi.mocked(filesUtils.isPathExists).mockResolvedValue(true)
+ vi.mocked(filesUtils.isPathIsDir).mockResolvedValue(false)
+ })
+
+ afterEach(() => {
+ configuration.applications.files.editors.drawio.externalServer = previousExternalServer
+ vi.clearAllMocks()
+ })
+
+ it('returns the local draw.io URL for .drawio files', async () => {
+ await expect(service.getSettings(mockSpace)).resolves.toEqual({
+ documentServerUrl: 'https://sync-in.test/drawio/'
+ })
+ })
+
+ it('supports .dwb files', async () => {
+ const workbookSpace = { ...mockSpace, realPath: '/path/to/diagram.dwb' } as SpaceEnv
+
+ await expect(service.getSettings(workbookSpace)).resolves.toEqual({
+ documentServerUrl: 'https://sync-in.test/drawio/'
+ })
+ })
+
+ it('returns the configured external draw.io URL', async () => {
+ const drawioConfig = configuration.applications.files.editors.drawio
+ const localExternalServer = drawioConfig.externalServer
+ drawioConfig.externalServer = 'https://embed.diagrams.net/'
+
+ try {
+ const externalService = new DrawioManager(contextManager)
+ await expect(externalService.getSettings(mockSpace)).resolves.toEqual({
+ documentServerUrl: 'https://embed.diagrams.net/'
+ })
+ } finally {
+ drawioConfig.externalServer = localExternalServer
+ }
+ })
+
+ it('rejects unsupported files', async () => {
+ const unsupportedSpace = { ...mockSpace, realPath: '/path/to/diagram.svg' } as SpaceEnv
+
+ await expect(service.getSettings(unsupportedSpace)).rejects.toThrow(new HttpException('Diagram format not supported', HttpStatus.BAD_REQUEST))
+ })
+
+ it('rejects missing files', async () => {
+ vi.mocked(filesUtils.isPathExists).mockResolvedValue(false)
+
+ await expect(service.getSettings(mockSpace)).rejects.toThrow(new HttpException('Diagram not found', HttpStatus.NOT_FOUND))
+ })
+
+ it('rejects directories', async () => {
+ vi.mocked(filesUtils.isPathIsDir).mockResolvedValue(true)
+
+ await expect(service.getSettings(mockSpace)).rejects.toThrow(new HttpException('Diagram must be a file', HttpStatus.BAD_REQUEST))
+ })
+
+ it('rejects a missing public origin for the local editor', async () => {
+ vi.spyOn(contextManager, 'publicOriginUrl').mockReturnValue(undefined)
+
+ await expect(service.getSettings(mockSpace)).rejects.toThrow(
+ new HttpException('Draw.io public URL is unavailable', HttpStatus.SERVICE_UNAVAILABLE)
+ )
+ })
+})
diff --git a/backend/src/applications/files/editors/drawio/drawio-manager.service.ts b/backend/src/applications/files/editors/drawio/drawio-manager.service.ts
new file mode 100644
index 00000000..37a8a119
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio-manager.service.ts
@@ -0,0 +1,39 @@
+import { HttpException, HttpStatus, Injectable } from '@nestjs/common'
+import path from 'node:path'
+import { configuration } from '../../../../configuration/config.environment'
+import { ContextManager } from '../../../../infrastructure/context/services/context-manager.service'
+import type { SpaceEnv } from '../../../spaces/models/space-env.model'
+import { isPathExists, isPathIsDir } from '../../utils/files'
+import { DRAWIO_EXTENSIONS, DRAWIO_INTERNAL_URI } from './drawio.constants'
+import type { DrawioSettingsDto } from './drawio.dtos'
+
+@Injectable()
+export class DrawioManager {
+ private readonly externalDrawioServer = configuration.applications.files.editors.drawio.externalServer || null
+
+ constructor(private readonly contextManager: ContextManager) {}
+
+ async getSettings(space: SpaceEnv): Promise<DrawioSettingsDto> {
+ if (!(await isPathExists(space.realPath))) {
+ throw new HttpException('Diagram not found', HttpStatus.NOT_FOUND)
+ }
+ if (await isPathIsDir(space.realPath)) {
+ throw new HttpException('Diagram must be a file', HttpStatus.BAD_REQUEST)
+ }
+ const extension = path.extname(space.realPath).slice(1).toLowerCase()
+ if (!DRAWIO_EXTENSIONS.has(extension)) {
+ throw new HttpException('Diagram format not supported', HttpStatus.BAD_REQUEST)
+ }
+
+ return { documentServerUrl: this.documentServerUrl() }
+ }
+
+ private documentServerUrl(): string {
+ if (this.externalDrawioServer) return this.externalDrawioServer
+ const publicOrigin = this.contextManager.publicOriginUrl()
+ if (!publicOrigin) {
+ throw new HttpException('Draw.io public URL is unavailable', HttpStatus.SERVICE_UNAVAILABLE)
+ }
+ return new URL(DRAWIO_INTERNAL_URI, publicOrigin).toString()
+ }
+}
diff --git a/backend/src/applications/files/editors/drawio/drawio.config.ts b/backend/src/applications/files/editors/drawio/drawio.config.ts
new file mode 100644
index 00000000..562e7dbf
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio.config.ts
@@ -0,0 +1,12 @@
+import { Transform } from 'class-transformer'
+import { IsBoolean, IsOptional, IsUrl } from 'class-validator'
+
+export class DrawioConfig {
+ @IsBoolean()
+ enabled = false
+
+ @Transform(({ value }) => (typeof value === 'string' ? value.trim() || null : value))
+ @IsOptional()
+ @IsUrl({ protocols: ['http', 'https'], require_protocol: true, require_tld: false, disallow_auth: true })
+ externalServer: string = null
+}
diff --git a/backend/src/applications/files/editors/drawio/drawio.constants.ts b/backend/src/applications/files/editors/drawio/drawio.constants.ts
index af5b7676..7bebd694 100644
--- a/backend/src/applications/files/editors/drawio/drawio.constants.ts
+++ b/backend/src/applications/files/editors/drawio/drawio.constants.ts
@@ -1,2 +1,4 @@
export const DRAWIO_INTERNAL_URI = '/drawio/' as const
export const DRAWIO_EXTENSIONS = new Set<string>(['drawio', 'dwb'])
+export const EMPTY_DRAWIO_XML =
+ '<mxfile><diagram name="Page-1"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>'
diff --git a/backend/src/applications/files/editors/drawio/drawio.controller.ts b/backend/src/applications/files/editors/drawio/drawio.controller.ts
new file mode 100644
index 00000000..0a6c16c6
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio.controller.ts
@@ -0,0 +1,19 @@
+import { Controller, Get, Request, UseGuards, UseInterceptors } from '@nestjs/common'
+import { ContextInterceptor } from '../../../../infrastructure/context/interceptors/context.interceptor'
+import { SpaceGuard } from '../../../spaces/guards/space.guard'
+import type { FastifySpaceRequest } from '../../../spaces/interfaces/space-request.interface'
+import { DrawioManager } from './drawio-manager.service'
+import type { DrawioSettingsDto } from './drawio.dtos'
+import { DRAWIO_ROUTE } from './drawio.routes'
+
+@Controller(DRAWIO_ROUTE.BASE)
+@UseGuards(SpaceGuard)
+export class DrawioController {
+ constructor(private readonly drawioManager: DrawioManager) {}
+
+ @Get(`${DRAWIO_ROUTE.DRAWIO}/${DRAWIO_ROUTE.SETTINGS}/*`)
+ @UseInterceptors(ContextInterceptor)
+ settings(@Request() req: FastifySpaceRequest): Promise<DrawioSettingsDto> {
+ return this.drawioManager.getSettings(req.space)
+ }
+}
diff --git a/backend/src/applications/files/editors/drawio/drawio.dtos.ts b/backend/src/applications/files/editors/drawio/drawio.dtos.ts
new file mode 100644
index 00000000..c821f050
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio.dtos.ts
@@ -0,0 +1,3 @@
+export interface DrawioSettingsDto {
+ documentServerUrl: string
+}
diff --git a/backend/src/applications/files/editors/drawio/drawio.module.ts b/backend/src/applications/files/editors/drawio/drawio.module.ts
new file mode 100644
index 00000000..619f0567
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio.module.ts
@@ -0,0 +1,9 @@
+import { Module } from '@nestjs/common'
+import { DrawioManager } from './drawio-manager.service'
+import { DrawioController } from './drawio.controller'
+
+@Module({
+ controllers: [DrawioController],
+ providers: [DrawioManager]
+})
+export class DrawioModule {}
diff --git a/backend/src/applications/files/editors/drawio/drawio.routes.ts b/backend/src/applications/files/editors/drawio/drawio.routes.ts
new file mode 100644
index 00000000..e4711d9e
--- /dev/null
+++ b/backend/src/applications/files/editors/drawio/drawio.routes.ts
@@ -0,0 +1,10 @@
+import { SPACES_ROUTE } from '../../../spaces/constants/routes'
+
+export const DRAWIO_ROUTE = {
+ BASE: SPACES_ROUTE.BASE,
+ DRAWIO: 'drawio',
+ SETTINGS: 'settings'
+} as const
+
+export const API_DRAWIO = `${DRAWIO_ROUTE.BASE}/${DRAWIO_ROUTE.DRAWIO}`
+export const API_DRAWIO_SETTINGS = `${API_DRAWIO}/${DRAWIO_ROUTE.SETTINGS}`
diff --git a/backend/src/applications/files/files.config.ts b/backend/src/applications/files/files.config.ts
index 2ecca9df..7ab3d77b 100644
--- a/backend/src/applications/files/files.config.ts
+++ b/backend/src/applications/files/files.config.ts
@@ -17,6 +17,7 @@ import {
import type { SampleDocumentGroup } from './constants/samples'
import { SAMPLE_DOCUMENT_GROUPS } from './constants/samples'
import { CollaboraOnlineConfig } from './editors/collabora-online/collabora-online.config'
+import { DrawioConfig } from './editors/drawio/drawio.config'
import { OnlyOfficeConfig } from './editors/only-office/only-office.config'
export class FilesContentIndexingOCRConfig {
@@ -77,6 +78,11 @@ export class FilesEditorsConfig {
@ValidateNested()
@Type(() => CollaboraOnlineConfig)
collabora: CollaboraOnlineConfig = new CollaboraOnlineConfig()
+
+ @IsNotEmptyObject()
+ @ValidateNested()
+ @Type(() => DrawioConfig)
+ drawio: DrawioConfig = new DrawioConfig()
}
export class FilesConfig {
diff --git a/backend/src/applications/files/files.module.ts b/backend/src/applications/files/files.module.ts
index 3ae38bd1..0b40cb61 100644
--- a/backend/src/applications/files/files.module.ts
+++ b/backend/src/applications/files/files.module.ts
@@ -6,6 +6,7 @@ import { FilesTasksController } from './files-tasks.controller'
import { FilesController } from './files.controller'
import { FilesContentStore } from './models/files-content-store'
import { CollaboraOnlineModule } from './editors/collabora-online/collabora-online.module'
+import { DrawioModule } from './editors/drawio/drawio.module'
import { OnlyOfficeModule } from './editors/only-office/only-office.module'
import { FilesContentIndexer } from './services/files-content-indexer.service'
import { FilesLockManager } from './services/files-lock-manager.service'
@@ -31,7 +32,8 @@ import { FilesFavoritesQueries } from './services/files-favorites-queries.servic
...(configuration.applications.files.editors.onlyoffice.enabled || configuration.applications.files.editors.eurooffice.enabled
? [OnlyOfficeModule]
: []),
- ...(configuration.applications.files.editors.collabora.enabled ? [CollaboraOnlineModule] : [])
+ ...(configuration.applications.files.editors.collabora.enabled ? [CollaboraOnlineModule] : []),
+ ...(configuration.applications.files.editors.drawio.enabled ? [DrawioModule] : [])
],
controllers: [FilesOperationsController, FilesController, FilesTasksController],
providers: [
diff --git a/backend/src/applications/files/services/files-manager.service.spec.ts b/backend/src/applications/files/services/files-manager.service.spec.ts
index 7e2bc939..e8cdaed7 100644
--- a/backend/src/applications/files/services/files-manager.service.spec.ts
+++ b/backend/src/applications/files/services/files-manager.service.spec.ts
@@ -886,16 +886,19 @@ describe(FilesManager.name, () => {
})
describe('creation', () => {
- it('mkFile should use sample document when requested', async () => {
- const space = makeSpace({ realPath: '/data/users/john/files/doc.docx' })
+ it.each([
+ ['doc.docx', 'sample.docx'],
+ ['diagram.drawio', 'sample.drawio']
+ ])('mkFile should use the %s sample document when requested', async (fileName, sampleName) => {
+ const space = makeSpace({ realPath: `/data/users/john/files/${fileName}` })
vi.mocked(filesUtils.isPathExists).mockResolvedValueOnce(false)
const emitSpy = vi.spyOn(FileEvent, 'emit')
await service.mkFile(user, space, false, true, true)
expect(filesUtils.copyFileContent).toHaveBeenCalledWith(
- expect.stringContaining('assets/samples/sample.docx'),
- '/data/users/john/files/doc.docx'
+ expect.stringContaining(`assets/samples/${sampleName}`),
+ `/data/users/john/files/${fileName}`
)
expect(emitSpy).toHaveBeenCalledWith('event', { user, space, action: ACTION.ADD, rPath: space.realPath })
})
diff --git a/backend/src/applications/files/services/files-manager.service.ts b/backend/src/applications/files/services/files-manager.service.ts
index 02d23ba7..8762308f 100644
--- a/backend/src/applications/files/services/files-manager.service.ts
+++ b/backend/src/applications/files/services/files-manager.service.ts
@@ -24,7 +24,7 @@ import { CACHE_LOCK_FILE_TTL } from '../constants/cache'
import { TAR_EXTENSION, TAR_GZ_EXTENSION, ZIP_EXTENSION } from '../constants/compress'
import { COMPRESSION_EXTENSION } from '../constants/files'
import { FILE_OPERATION } from '../constants/operations'
-import { ALL_DOCUMENT_TYPES, DEFAULT_DOCUMENT_TYPES, SAMPLE_PATH_WITHOUT_EXT } from '../constants/samples'
+import { SAMPLE_DOCUMENT_EXTENSIONS, SAMPLE_PATH_WITHOUT_EXT } from '../constants/samples'
import { CompressFileDto, DownloadFileDto } from '../dto/file-operations.dto'
import type { DeleteFileOptions } from '../interfaces/delete-file.interface'
import { FileDBProps } from '../interfaces/file-db-props.interface'
@@ -384,11 +384,7 @@ export class FilesManager {
}
// use sample documents when possible
const fileExtension = path.extname(space.realPath).slice(1)
- if (
- checkDocument &&
- Object.values(DEFAULT_DOCUMENT_TYPES).indexOf(fileExtension) === -1 &&
- Object.values(ALL_DOCUMENT_TYPES).indexOf(fileExtension) > -1
- ) {
+ if (checkDocument && SAMPLE_DOCUMENT_EXTENSIONS.has(fileExtension)) {
const srcSample = path.join(__dirname, `${SAMPLE_PATH_WITHOUT_EXT}.${fileExtension}`)
await copyFileContent(srcSample, space.realPath)
// emit file event
diff --git a/backend/src/applications/files/utils/files.spec.ts b/backend/src/applications/files/utils/files.spec.ts
index 8b39322e..6eeb7a46 100644
--- a/backend/src/applications/files/utils/files.spec.ts
+++ b/backend/src/applications/files/utils/files.spec.ts
@@ -7,6 +7,7 @@ import { FileError } from '../models/file-error'
import { storageQuotaExceededError } from './errors'
import {
createSizeLimiter,
+ getMimeType,
isCrossDevice,
isInternalTemporaryEntry,
isInternalTemporaryPath,
@@ -82,6 +83,13 @@ describe(sanitizeName.name, () => {
})
})
+describe(getMimeType.name, () => {
+ it('returns draw.io MIME types for diagrams and workbooks', () => {
+ expect(getMimeType('/path/to/diagram.drawio', false)).toBe('application-x-drawio')
+ expect(getMimeType('/path/to/diagram.dwb', false)).toBe('application-x-drawio-wb')
+ })
+})
+
describe(isCrossDevice.name, () => {
afterEach(() => {
vi.restoreAllMocks()
diff --git a/backend/src/configuration/config.environment.ts b/backend/src/configuration/config.environment.ts
index 160f8cb3..23c74a7a 100755
--- a/backend/src/configuration/config.environment.ts
+++ b/backend/src/configuration/config.environment.ts
@@ -17,6 +17,7 @@ export const serverConfig: ServerConfig = {
files: {
editors: {
collabora: configuration.applications.files.editors.collabora.enabled,
+ drawio: configuration.applications.files.editors.drawio.enabled,
eurooffice: configuration.applications.files.editors.eurooffice.enabled,
onlyoffice: configuration.applications.files.editors.onlyoffice.enabled
},
diff --git a/docker/config/drawio/docker-compose.drawio.yaml b/docker/config/drawio/docker-compose.drawio.yaml
new file mode 100644
index 00000000..4cd76f13
--- /dev/null
+++ b/docker/config/drawio/docker-compose.drawio.yaml
@@ -0,0 +1,12 @@
+services:
+ drawio:
+ image: jgraph/drawio
+ container_name: drawio
+ restart: always
+ logging:
+ driver: json-file
+ options:
+ max-size: "25m"
+ max-file: "5"
+ networks:
+ - sync_in_network
diff --git a/docker/config/nginx/docker-compose.nginx.yaml b/docker/config/nginx/docker-compose.nginx.yaml
index 80572e17..2f915548 100644
--- a/docker/config/nginx/docker-compose.nginx.yaml
+++ b/docker/config/nginx/docker-compose.nginx.yaml
@@ -8,6 +8,7 @@ services:
- ./onlyoffice.conf:/etc/nginx/onlyoffice.conf
- ./collabora.conf:/etc/nginx/collabora.conf
- ./eurooffice.conf:/etc/nginx/eurooffice.conf
+ - ./drawio.conf:/etc/nginx/drawio.conf
ports:
- "80:80"
logging:
@@ -18,4 +19,4 @@ services:
depends_on:
- sync_in
networks:
- - sync_in_network
\ No newline at end of file
+ - sync_in_network
diff --git a/docker/config/nginx/drawio.conf b/docker/config/nginx/drawio.conf
new file mode 100644
index 00000000..322809b7
--- /dev/null
+++ b/docker/config/nginx/drawio.conf
@@ -0,0 +1,12 @@
+location ^~ /drawio/ {
+ # Allow resource loading from the sandboxed iframe's opaque origin.
+ add_header Access-Control-Allow-Origin "*" always;
+ proxy_pass http://drawio:8080/;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Host $http_host;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header Host $http_host;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $connection_upgrade;
+}
diff --git a/docker/config/nginx/nginx.conf b/docker/config/nginx/nginx.conf
index 1b2f0cdc..25b7981b 100644
--- a/docker/config/nginx/nginx.conf
+++ b/docker/config/nginx/nginx.conf
@@ -91,4 +91,9 @@ server {
# and you are not using an external URL.
# Uncomment the line below to enable it:
# include eurooffice.conf;
+
+ # NOTE: This is only needed when the draw.io Docker container is running locally
+ # and you are not using an external URL.
+ # Uncomment the line below to enable it:
+ # include drawio.conf;
}
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index 37c4789a..fe29120d 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -3,6 +3,7 @@
# - ./config/onlyoffice/docker-compose.onlyoffice.yaml
# - ./config/collabora/docker-compose.collabora.yaml
# - ./config/eurooffice/docker-compose.eurooffice.yaml
+# - ./config/drawio/docker-compose.drawio.yaml
# - ./config/sync-in-desktop-releases/docker-compose.sync-in-desktop-releases.yaml
name: sync-in
diff --git a/docker/environment.yaml b/docker/environment.yaml
index 3964c51f..19c9e582 100644
--- a/docker/environment.yaml
+++ b/docker/environment.yaml
@@ -21,6 +21,8 @@ applications:
editors:
collabora:
enabled: false
+ drawio:
+ enabled: false
onlyoffice:
enabled: false
# Required when enabled. Must match JWT_SECRET in the OnlyOffice container.
diff --git a/environment/environment.dist.yaml b/environment/environment.dist.yaml
index ea52d196..750c0197 100644
--- a/environment/environment.dist.yaml
+++ b/environment/environment.dist.yaml
@@ -378,10 +378,10 @@ applications:
# default: false
showHiddenFiles: false
# Optional document groups shown in the "new document" dialog.
- # options: `microsoft` | `opendocument`
+ # options: `microsoft` | `opendocument` | `drawio`
# use [] to only show Text and Markdown
- # default: [opendocument, microsoft]
- sampleDocuments: [opendocument, microsoft]
+ # default: [opendocument, microsoft, drawio]
+ sampleDocuments: [opendocument, microsoft, drawio]
editors:
onlyoffice:
# enable onlyoffice integration
@@ -390,9 +390,9 @@ applications:
# Secret used for jwt tokens, it must be the same on the onlyoffice server
# required
secret:
- # If no external server is configured, the local Nginx service from the Docker Compose setup is used.
- # If an external server is configured, it will be used instead.
- # Note: when using an external server (e.g.: https://onlyoffice.domain.com), make sure it is accessible from the client/browser.
+ # If unset, the local Docker Compose service is used through Nginx.
+ # If set, this external URL is used instead and must be accessible from the client/browser.
+ # example: https://onlyoffice.domain.com
# default: null
externalServer:
# If you use https, set to `true`.
@@ -405,8 +405,9 @@ applications:
# Secret used for jwt tokens, it must be the same on the Euro-Office server
# required
secret:
- # If an external server is configured, it will be used.
- # Note: make sure it is accessible from the client/browser.
+ # If unset, the local Docker Compose service is used through Nginx.
+ # If set, this external URL is used instead and must be accessible from the client/browser.
+ # example: https://eurooffice.domain.com
# default: null
externalServer:
# If you use https, set to `true`.
@@ -416,9 +417,18 @@ applications:
# enable collabora online integration
# default: false
enabled: false
- # If no external server is configured, the local Nginx service from the Docker Compose setup is used.
- # If an external server is configured, it will be used instead.
- # Note: when using an external server (e.g.: https://collabora.domain.com), make sure it is accessible from the client/browser.
+ # If unset, the local Docker Compose service is used through Nginx.
+ # If set, this external URL is used instead and must be accessible from the client/browser.
+ # example: https://collabora.domain.com
+ # default: null
+ externalServer:
+ drawio:
+ # enable draw.io integration
+ # default: false
+ enabled: false
+ # If unset, the local Docker Compose service is used through Nginx.
+ # If set, this external URL is used instead and must be accessible from the client/browser.
+ # example: https://drawio.domain.com
# default: null
externalServer:
# Client application repository configuration
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 1fe3489a..3254b494 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
@@ -85,6 +85,22 @@
<div [style.height.px]="currentHeight" class="d-flex p-4" l10nTranslate>No editor found</div>
}
}
+ @case (SHORT_MIME.DIAGRAM) {
+ @defer (on immediate) {
+ <app-files-viewer-drawio
+ [currentHeight]="currentHeight - 5"
+ [file]="currentFile"
+ [isWriteable]="isWriteable"
+ [modalClosing]="modalClosing()"
+ (viewerReady)="editableViewerReady.set(true)"
+ [(isReadonly)]="isReadonly">
+ </app-files-viewer-drawio>
+ } @loading (after 100ms; minimum 200ms) {
+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>
+ } @error {
+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>
+ }
+ }
@case (SHORT_MIME.MARKDOWN) {
@defer (on immediate) {
<app-files-viewer-markdown
diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
index cb41e480..bf3d6e86 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
@@ -10,6 +10,7 @@ import { StoreService } from '../../../../store/store.service'
import { SHORT_MIME } from '../../files.constants'
import { FileModel } from '../../models/file.model'
import { FilesViewerCollaboraOnlineComponent } from '../viewers/files-viewer-collabora-online.component'
+import { FilesViewerDrawioComponent } from '../viewers/files-viewer-drawio.component'
import { FilesViewerImageComponent } from '../viewers/files-viewer-image.component'
import { FilesViewerMarkdownComponent } from '../viewers/files-viewer-markdown.component'
import { FilesViewerMediaComponent } from '../viewers/files-viewer-media.component'
@@ -29,6 +30,7 @@ import { FilesViewerTextComponent } from '../viewers/files-viewer-text.component
LucideDynamicIcon,
FilesViewerOnlyOfficeComponent,
FilesViewerCollaboraOnlineComponent,
+ FilesViewerDrawioComponent,
L10nTranslateDirective
],
templateUrl: 'files-viewer-dialog.component.html'
@@ -68,7 +70,8 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {
}
onClose() {
- const isEditableViewer = this.hookedShortMime === SHORT_MIME.TEXT || this.hookedShortMime === SHORT_MIME.MARKDOWN
+ const isEditableViewer =
+ this.hookedShortMime === SHORT_MIME.TEXT || this.hookedShortMime === SHORT_MIME.MARKDOWN || this.hookedShortMime === SHORT_MIME.DIAGRAM
if (isEditableViewer && this.editableViewerReady()) {
// Prevent closing the modal without saving when using text-based editors
this.modalClosing.set(true)
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-drawio.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-drawio.component.ts
new file mode 100644
index 00000000..ade88cbf
--- /dev/null
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-drawio.component.ts
@@ -0,0 +1,285 @@
+import { HttpClient, HttpErrorResponse } from '@angular/common/http'
+import { Component, ElementRef, HostListener, inject, OnDestroy, OnInit, signal, viewChild } from '@angular/core'
+import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
+import type { DrawioSettingsDto } from '@sync-in-server/backend/src/applications/files/editors/drawio/drawio.dtos'
+import { EMPTY_DRAWIO_XML } from '@sync-in-server/backend/src/applications/files/editors/drawio/drawio.constants'
+import { API_DRAWIO_SETTINGS } from '@sync-in-server/backend/src/applications/files/editors/drawio/drawio.routes'
+import { L10nTranslateDirective } from 'angular-l10n'
+import { FilesViewerUnsavedChangesComponent } from './components/files-viewer-unsaved-changes.component'
+import { FilesViewerEditableBase } from './files-viewer-editable-base'
+import type { DrawioEditorEvent } from './interfaces/files-viewer-drawio.interface'
+
+@Component({
+ selector: 'app-files-viewer-drawio',
+ imports: [L10nTranslateDirective, FilesViewerUnsavedChangesComponent],
+ styles: [
+ `
+ .drawio-viewer {
+ position: relative;
+ }
+
+ .drawio-viewer__frame {
+ width: 100%;
+ height: 100%;
+ border: 0;
+ }
+
+ .drawio-viewer__state {
+ height: 100%;
+ }
+ `
+ ],
+ template: `
+ <div class="drawio-viewer" [style.height.px]="currentHeight()">
+ @if (loading()) {
+ <div class="drawio-viewer__state d-flex align-items-center justify-content-center" role="status">
+ <span class="spinner-border text-primary" aria-hidden="true"></span>
+ <span class="visually-hidden" l10nTranslate>Loading...</span>
+ </div>
+ } @else if (loadFailed()) {
+ <div class="drawio-viewer__state d-flex align-items-center justify-content-center p-4" l10nTranslate>Unable to open document</div>
+ } @else if (iframeSrc()) {
+ @if (warnOnUnsavedChanges()) {
+ <app-files-viewer-unsaved-changes
+ [saving]="isSaving()"
+ (saveAndExit)="saveAndExit()"
+ (closeWithoutSaving)="onClose()"
+ (keepEditing)="warnOnUnsavedChanges.set(false)"
+ />
+ }
+ @if (isExternalEditor()) {
+ <iframe
+ #editorFrame
+ class="drawio-viewer__frame"
+ [src]="iframeSrc()"
+ title="Draw.io"
+ allow="clipboard-read *; clipboard-write *; fullscreen"
+ sandbox="allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts"
+ allowfullscreen
+ >
+ </iframe>
+ } @else {
+ <iframe
+ #editorFrame
+ class="drawio-viewer__frame"
+ [src]="iframeSrc()"
+ title="Draw.io"
+ allow="clipboard-read *; clipboard-write *; fullscreen"
+ sandbox="allow-downloads allow-forms allow-modals allow-popups allow-scripts"
+ allowfullscreen
+ >
+ </iframe>
+ }
+ }
+ </div>
+ `
+})
+export class FilesViewerDrawioComponent extends FilesViewerEditableBase implements OnInit, OnDestroy {
+ protected readonly loading = signal(true)
+ protected readonly loadFailed = signal(false)
+ protected readonly iframeSrc = signal<SafeResourceUrl | null>(null)
+ protected readonly isExternalEditor = signal(false)
+ private readonly editorFrame = viewChild<ElementRef<HTMLIFrameElement>>('editorFrame')
+ private readonly httpClient = inject(HttpClient)
+ private readonly sanitizer = inject(DomSanitizer)
+ private content = ''
+ private savedContent = ''
+ private editorOrigin = 'null'
+ private editorServerUrl = ''
+ // draw.io can emit another save while the previous HTTP upload is still running.
+ // Coalesce those events into one follow-up upload containing the latest XML.
+ private savePending = false
+ private closeAfterSave = false
+
+ constructor() {
+ super()
+ }
+
+ ngOnInit() {
+ this.httpClient.get<DrawioSettingsDto>(`${API_DRAWIO_SETTINGS}/${this.file().encodedPath}`).subscribe({
+ next: (settings) => {
+ try {
+ const editorUrl = new URL(settings.documentServerUrl)
+ if (editorUrl.protocol !== 'http:' && editorUrl.protocol !== 'https:') throw new Error('Unsupported draw.io URL')
+ this.editorServerUrl = editorUrl.toString()
+ if (editorUrl.origin !== window.location.origin) {
+ this.editorOrigin = editorUrl.origin
+ this.isExternalEditor.set(true)
+ }
+ this.isSupported.set(true)
+ this.loadContent().catch(console.error)
+ } catch (e) {
+ this.handleLoadError(e)
+ }
+ },
+ error: (e: HttpErrorResponse) => this.handleLoadError(e)
+ })
+ }
+
+ override ngOnDestroy() {
+ super.ngOnDestroy()
+ }
+
+ @HostListener('window:message', ['$event'])
+ onMessage(event: MessageEvent) {
+ const frame = this.editorFrame()?.nativeElement
+ if (!frame || event.source !== frame.contentWindow || event.origin !== this.editorOrigin) return
+
+ let data: DrawioEditorEvent
+ try {
+ data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data
+ } catch {
+ return
+ }
+ if (!data || typeof data.event !== 'string') return
+
+ switch (data.event) {
+ case 'ready':
+ if (this.isReadonlyView()) {
+ this.postToEditor({ action: 'create', data: { type: 'xml', data: this.content } })
+ }
+ break
+ case 'init':
+ if (this.isReadonlyView()) return
+ this.postToEditor({ action: 'load', xml: this.content, autosave: 1, title: this.file().name })
+ if (this.isModified()) this.persist()
+ break
+ case 'save':
+ if (typeof data.xml === 'string') this.queueSave(data.xml, data.exit === true)
+ break
+ case 'autosave':
+ if (typeof data.xml === 'string') this.trackChanges(data.xml)
+ break
+ case 'exit':
+ this.requestClose()
+ break
+ }
+ }
+
+ protected currentFileContent(): string {
+ return this.content
+ }
+
+ protected onContentLoaded(content: string) {
+ this.savedContent = content
+ this.content = content.trim() ? content : EMPTY_DRAWIO_XML
+ this.isModified.set(this.content !== this.savedContent && !this.isReadonly() && this.isWriteable())
+ this.configureIframe()
+ this.loading.set(false)
+ }
+
+ protected override onContentSaved(content: string) {
+ this.savedContent = content
+ this.postToEditor({ action: 'status', message: '', modified: this.content !== content })
+ }
+
+ protected override onContentLoadError(error: HttpErrorResponse) {
+ this.handleLoadError(error)
+ }
+
+ protected override onSaveFinished(success: boolean) {
+ if (!success) {
+ // A failed "save and exit" must not close the editor after an unrelated later save.
+ this.savePending = false
+ this.closeAfterSave = false
+ this.postToEditor({ action: 'status', message: 'Save failed.', modified: true })
+ return
+ }
+
+ if (this.isModified() && (this.savePending || this.closeAfterSave)) {
+ // The completed request saved an older snapshot; flush the latest XML before closing.
+ this.savePending = false
+ this.persist()
+ return
+ }
+
+ this.savePending = false
+ if (this.closeAfterSave && !this.isModified()) {
+ this.closeAfterSave = false
+ this.onClose().catch(console.error)
+ }
+ }
+
+ protected saveAndExit() {
+ this.warnOnUnsavedChanges.set(false)
+ this.closeAfterSave = true
+ if (this.isSaving()) return
+ if (this.isModified()) {
+ this.persist()
+ } else {
+ this.closeAfterSave = false
+ this.onClose().catch(console.error)
+ }
+ }
+
+ private configureIframe() {
+ const editorUrl = new URL(this.editorServerUrl)
+ editorUrl.searchParams.set('dark', this.currentTheme === 'dark' ? '1' : '0')
+ editorUrl.searchParams.set('lang', this.locale.language)
+ if (this.isReadonlyView()) {
+ editorUrl.searchParams.set('chrome', '0')
+ editorUrl.searchParams.set('lightbox', '1')
+ editorUrl.searchParams.set('layers', '1')
+ editorUrl.searchParams.set('nav', '1')
+ editorUrl.searchParams.set('title', this.file().name)
+ editorUrl.hash = `create=${encodeURIComponent(JSON.stringify({ type: 'message' }))}`
+ } else {
+ editorUrl.searchParams.set('embed', '1')
+ editorUrl.searchParams.set('spin', '1')
+ editorUrl.searchParams.set('proto', 'json')
+ editorUrl.searchParams.set('noExitBtn', '1')
+ }
+ this.iframeSrc.set(this.sanitizer.bypassSecurityTrustResourceUrl(editorUrl.toString()))
+ }
+
+ private isReadonlyView(): boolean {
+ return this.isReadonly() || !this.isWriteable()
+ }
+
+ private queueSave(xml: string, exit: boolean) {
+ if (this.isReadonly() || !this.isWriteable()) return
+ this.trackChanges(xml)
+ this.closeAfterSave ||= exit
+ if (this.isSaving()) {
+ this.savePending = true
+ return
+ }
+ if (this.isModified()) {
+ this.persist()
+ } else if (this.closeAfterSave) {
+ this.closeAfterSave = false
+ this.onClose().catch(console.error)
+ }
+ }
+
+ private trackChanges(xml: string) {
+ if (this.isReadonly() || !this.isWriteable()) return
+ this.content = xml
+ this.isModified.set(this.content !== this.savedContent)
+ }
+
+ private requestClose() {
+ if (this.isSaving()) return
+ if (this.isModified() && !this.isReadonly()) {
+ this.warnOnUnsavedChanges.set(true)
+ } else {
+ this.onClose().catch(console.error)
+ }
+ }
+
+ private persist() {
+ this.save()
+ }
+
+ private postToEditor(message: object) {
+ const targetOrigin = this.editorOrigin === 'null' ? '*' : this.editorOrigin
+ this.editorFrame()?.nativeElement.contentWindow?.postMessage(JSON.stringify(message), targetOrigin)
+ }
+
+ private handleLoadError(error: unknown) {
+ this.loading.set(false)
+ this.loadFailed.set(true)
+ const message = error instanceof HttpErrorResponse ? error.error?.message || error.message : `${error}`
+ this.layout.sendNotification('error', 'Unable to open document', message)
+ }
+}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts
index a63a7d29..5165406a 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts
@@ -19,6 +19,7 @@ import { TooltipDirective } from 'ngx-bootstrap/tooltip'
import { firstValueFrom } from 'rxjs'
import { type AppWindow, themeDark } from '../../../../layout/layout.interfaces'
import { LayoutService } from '../../../../layout/layout.service'
+import { MAX_CLIENT_EDITOR_FILE_SIZE } from '../../files.constants'
import { FileModel } from '../../models/file.model'
import { FilesService } from '../../services/files.service'
import { FilesUploadService } from '../../services/files-upload.service'
@@ -45,7 +46,7 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
private readonly filesUpload = inject(FilesUploadService)
private readonly subscription = this.layout.switchTheme.subscribe((layout: string) => (this.currentTheme = layout === themeDark ? 'dark' : 'light'))
private isDestroyed = false
- private unlockRequested = false
+ private unlockPromise: Promise<boolean> | null = null
protected constructor() {
effect(() => {
@@ -95,7 +96,7 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
this.layout.sendNotification('error', 'Unable to open document', this.file().name, e)
}
- protected onSaveFinished(): void {
+ protected onSaveFinished(_success: boolean): void {
return
}
@@ -105,34 +106,43 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
this.isReadonly.set(false)
}
} else {
- await this.unlockFile()
- this.isReadonly.set(true)
+ if (await this.unlockFile()) {
+ this.isReadonly.set(true)
+ }
}
}
protected save(exit = false) {
if (!this.canSave()) return
- this.isSaving.set(true)
const content = this.currentFileContent()
+ const contentSize = new Blob([content]).size
+ if (contentSize >= MAX_CLIENT_EDITOR_FILE_SIZE) {
+ this.onSaveFinished(false)
+ this.layout.sendNotification('warning', 'Unable to save document', 'File size limit exceeded')
+ return
+ }
+ this.isSaving.set(true)
this.filesUpload.uploadFileContent(this.file(), content, true).subscribe({
next: () => {
if (this.isDestroyed) return
this.onContentSaved(content)
- this.isModified.set(false)
+ // The editor may have changed while this content snapshot was uploading.
+ // Only mark it clean when the current content still matches that snapshot.
+ this.isModified.set(this.currentFileContent() !== content)
this.isSaving.set(false)
this.warnOnUnsavedChanges.set(false)
- if (exit) {
+ if (exit && !this.isModified()) {
this.onClose().catch(console.error)
} else {
- this.onSaveFinished()
+ this.onSaveFinished(true)
}
- this.file().updateSize(new Blob([content]).size)
+ this.file().updateSize(contentSize)
this.file().updateHTimeAgo()
},
error: (e: HttpErrorResponse) => {
if (this.isDestroyed) return
this.isSaving.set(false)
- this.onSaveFinished()
+ this.onSaveFinished(false)
this.layout.sendNotification('error', 'Unable to save document', e.error.message)
}
})
@@ -160,9 +170,7 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
protected async onClose() {
if (this.isSaving()) return
- if (!this.isReadonly()) {
- await this.unlockFile()
- }
+ if (!this.isReadonly() && !(await this.unlockFile())) return
this.layout.closeDialog(null, this.file().id)
}
@@ -180,7 +188,6 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
if (!this.isSupported() || !this.isWriteable()) return false
try {
const lock: FileLockProps = await firstValueFrom(this.filesServices.lock(this.file()))
- this.unlockRequested = false
this.file.update((f) => {
f.lock = lock
return f
@@ -196,30 +203,42 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
}
}
- protected async unlockFile() {
- if (this.unlockRequested || !this.isSupported() || !this.isWriteable()) return
- this.unlockRequested = true
+ protected unlockFile(): Promise<boolean> {
+ if (!this.file().lock) return Promise.resolve(true)
+ // Close, toggle and destroy paths must await the same request instead of racing each other.
+ if (this.unlockPromise) return this.unlockPromise
+
+ this.unlockPromise = this.releaseLock().finally(() => {
+ this.unlockPromise = null
+ })
+ return this.unlockPromise
+ }
+
+ private async releaseLock(): Promise<boolean> {
try {
await firstValueFrom(this.filesServices.unlock(this.file()))
this.file.update((f) => {
delete f.lock
return f
})
+ return true
} catch (e) {
- this.lockError(e as HttpErrorResponse)
+ // Keep the local lock and the editor state intact so a later close or toggle can retry.
+ this.layout.sendNotification('warning', 'Unable to unlock file', this.file().name, e as HttpErrorResponse)
+ return false
}
}
private unlockFileOnPageUnload() {
// Firefox may cancel this request when closing the tab before it reaches the backend.
- if (this.unlockRequested || this.isReadonly() || !this.file().lock || !this.isSupported() || !this.isWriteable()) return
- this.unlockRequested = true
- this.filesServices.unlock(this.file()).subscribe({ error: () => undefined })
+ if (this.isReadonly() || !this.file().lock) return
+ // Reuse an existing unlock promise so destruction cannot start a competing request.
+ void this.unlockFile()
}
private lockError(e: HttpErrorResponse) {
+ // Lock availability is independent from editor support: keep the viewer read-only and retryable.
this.isReadonly.set(true)
- this.isSupported.set(false)
if (e.error?.owner) {
const lock: FileLockProps = e.error
this.file.update((f) => {
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts
index c2efdd38..5ed0136a 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts
@@ -451,7 +451,7 @@ export class FilesViewerMarkdownComponent extends FilesViewerEditableBase implem
this.savedContent = content
}
- protected override onSaveFinished() {
+ protected override onSaveFinished(_success: boolean) {
this.scheduleEditorFocus(this.isSourceMode() ? 'source' : 'visual', undefined, true)
}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
index 57f1114f..c617f707 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
@@ -172,7 +172,7 @@ export class FilesViewerTextComponent extends FilesViewerEditableBase implements
this.savedContent = content
}
- protected override onSaveFinished() {
+ protected override onSaveFinished(_success: boolean) {
this.scheduleEditorFocus(undefined, true)
}
diff --git a/frontend/src/app/applications/files/components/viewers/interfaces/files-viewer-drawio.interface.ts b/frontend/src/app/applications/files/components/viewers/interfaces/files-viewer-drawio.interface.ts
new file mode 100644
index 00000000..4eed8e6b
--- /dev/null
+++ b/frontend/src/app/applications/files/components/viewers/interfaces/files-viewer-drawio.interface.ts
@@ -0,0 +1,5 @@
+export interface DrawioEditorEvent {
+ event: string
+ exit?: boolean
+ xml?: string
+}
diff --git a/frontend/src/app/applications/files/files.constants.ts b/frontend/src/app/applications/files/files.constants.ts
index 853f11d2..3420d744 100644
--- a/frontend/src/app/applications/files/files.constants.ts
+++ b/frontend/src/app/applications/files/files.constants.ts
@@ -14,8 +14,7 @@ export function getAssetsMimeUrl(asset: string): string {
export const linkProtected = `${assetsUrl}/protected.png`
export const defaultMimeUrl = getAssetsMimeUrl(mimeFile)
-export const MAX_TEXT_FILE_SIZE = 25 * 1024 * 1024 // 25 MB
-export const MAX_DIAGRAM_FILE_SIZE = 10 * 1024 * 1024 // 10 MB
+export const MAX_CLIENT_EDITOR_FILE_SIZE = 25 * 1024 * 1024 // 25 MB
export const COMPRESSIBLE_MIMES = new Set(['application-gzip', 'application-zip', 'application-x-tar'])
export const SHORT_MIME = {
DIAGRAM: 'diagram',
diff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.ts
index 141b77d0..fccc7a9b 100644
--- a/frontend/src/app/applications/files/services/files.service.ts
+++ b/frontend/src/app/applications/files/services/files.service.ts
@@ -53,7 +53,7 @@ import { type FilesOverwriteAction, FilesOverwriteDialogComponent } from '../com
import type { FilesViewerDialogComponent as FilesViewerDialogComponentState } from '../components/dialogs/files-viewer-dialog.component'
import { FilesViewerSelectDialog } from '../components/dialogs/files-viewer-select-dialog.component'
import { fileLockPropsToString } from '../components/utils/file-lock.utils'
-import { MAX_DIAGRAM_FILE_SIZE, MAX_TEXT_FILE_SIZE, SHORT_MIME } from '../files.constants'
+import { MAX_CLIENT_EDITOR_FILE_SIZE, SHORT_MIME } from '../files.constants'
import { FileContentModel } from '../models/file-content.model'
import { FileFavoriteModel } from '../models/file-favorite.model'
import { FileRecentModel } from '../models/file-recent.model'
@@ -388,7 +388,7 @@ export class FilesService {
}
private async openViewerAfterAvailabilityCheck(file: FileModel, directoryFiles: FileModel[], permissions: string): Promise<void> {
- // This check is only used for the text viewer; other viewers are read-only or enforce permissions on the backend.
+ // Client-side editable viewers use this flag; office editors enforce permissions on the backend.
const isWriteable = !file?.lock?.isExclusive && permissions.includes(SPACE_OPERATION.MODIFY)
const mode: FILE_MODE = isWriteable ? FILE_MODE.EDIT : FILE_MODE.VIEW
@@ -481,14 +481,14 @@ export class FilesService {
}
private async viewerHook(file: FileModel): Promise<ViewerHookResult> {
- if (file.shortMime === SHORT_MIME.DIAGRAM && file.size >= MAX_DIAGRAM_FILE_SIZE) {
+ if (file.shortMime === SHORT_MIME.DIAGRAM && file.size >= MAX_CLIENT_EDITOR_FILE_SIZE) {
return { action: 'download', message: this.fileSizeLimitExceededMessage }
}
if (file.shortMime === SHORT_MIME.TEXT || file.shortMime === SHORT_MIME.MARKDOWN) {
if (file.shortMime === SHORT_MIME.TEXT && (await this.hasBinaryContent(file))) {
return { action: 'download' }
}
- if (file.size >= MAX_TEXT_FILE_SIZE) {
+ if (file.size >= MAX_CLIENT_EDITOR_FILE_SIZE) {
// Download if too large
return { action: 'download', message: this.fileSizeLimitExceededMessage }
}
diff --git a/frontend/src/app/store/store.service.ts b/frontend/src/app/store/store.service.ts
index a44de97e..e953c6c2 100644
--- a/frontend/src/app/store/store.service.ts
+++ b/frontend/src/app/store/store.service.ts
@@ -31,7 +31,7 @@ export class StoreService {
twoFaEnabled: false,
mailServerEnabled: false,
files: {
- editors: { collabora: false, eurooffice: false, onlyoffice: false },
+ editors: { collabora: false, drawio: false, eurooffice: false, onlyoffice: false },
sampleDocuments: ALL_DOCUMENT_TYPES
}
})
diff --git a/frontend/src/assets/mimes/application-x-drawio-wb.svg b/frontend/src/assets/mimes/application-x-drawio-wb.svg
new file mode 120000
index 00000000..99dc158e
--- /dev/null
+++ b/frontend/src/assets/mimes/application-x-drawio-wb.svg
@@ -0,0 +1 @@
+application-x-drawio.svg
\ No newline at end of file
diff --git a/frontend/src/assets/mimes/application-x-drawio.svg b/frontend/src/assets/mimes/application-x-drawio.svg
new file mode 100644
index 00000000..3a0c6025
--- /dev/null
+++ b/frontend/src/assets/mimes/application-x-drawio.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Diagram">
+ <rect width="64" height="64" rx="12" fill="#f08705"/>
+ <path d="M20 21h24v22H20z" fill="none" stroke="#fff" stroke-width="4"/>
+ <circle cx="20" cy="21" r="5" fill="#fff"/>
+ <circle cx="44" cy="21" r="5" fill="#fff"/>
+ <circle cx="20" cy="43" r="5" fill="#fff"/>
+ <circle cx="44" cy="43" r="5" fill="#fff"/>
+ <circle cx="32" cy="32" r="5" fill="#fff"/>
+</svg>
+
diff --git a/frontend/src/i18n/de.json b/frontend/src/i18n/de.json
index 81a7737b..42b9d3ed 100644
--- a/frontend/src/i18n/de.json
+++ b/frontend/src/i18n/de.json
@@ -386,6 +386,7 @@
"File name": "Dateiname",
"File permissions": "Dateiberechtigungen",
"Document": "Dokument",
+ "Diagram": "Diagramm",
"Spreadsheet": "Tabellenkalkulation",
"Presentation": "Präsentation",
"Text": "Text",
diff --git a/frontend/src/i18n/es.json b/frontend/src/i18n/es.json
index 058ddde8..0ea66245 100644
--- a/frontend/src/i18n/es.json
+++ b/frontend/src/i18n/es.json
@@ -386,6 +386,7 @@
"File name": "Nombre del archivo",
"File permissions": "Permisos del archivo",
"Document": "Documento",
+ "Diagram": "Diagrama",
"Spreadsheet": "Hoja de cálculo",
"Presentation": "Presentación",
"Text": "Texto",
diff --git a/frontend/src/i18n/fr.json b/frontend/src/i18n/fr.json
index eb67a6de..dac1d64c 100644
--- a/frontend/src/i18n/fr.json
+++ b/frontend/src/i18n/fr.json
@@ -386,6 +386,7 @@
"File name": "Nom du fichier",
"File permissions": "Permissions du fichier",
"Document": "Document",
+ "Diagram": "Diagramme",
"Spreadsheet": "Tableur",
"Presentation": "Présentation",
"Text": "Texte",
diff --git a/frontend/src/i18n/hi.json b/frontend/src/i18n/hi.json
index bf240d8e..6e929b80 100644
--- a/frontend/src/i18n/hi.json
+++ b/frontend/src/i18n/hi.json
@@ -386,6 +386,7 @@
"File name": "फ़ाइल का नाम",
"File permissions": "फ़ाइल अनुमतियाँ",
"Document": "दस्तावेज़",
+ "Diagram": "आरेख",
"Spreadsheet": "स्प्रेडशीट",
"Presentation": "प्रस्तुति",
"Text": "पाठ",
diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json
index 5aacb8e4..2c6aa34f 100644
--- a/frontend/src/i18n/it.json
+++ b/frontend/src/i18n/it.json
@@ -386,6 +386,7 @@
"File name": "Nome del file",
"File permissions": "Permessi del file",
"Document": "Documento",
+ "Diagram": "Diagramma",
"Spreadsheet": "Foglio di calcolo",
"Presentation": "Presentazione",
"Text": "Testo",
diff --git a/frontend/src/i18n/ja.json b/frontend/src/i18n/ja.json
index 798ae92c..feb5a162 100644
--- a/frontend/src/i18n/ja.json
+++ b/frontend/src/i18n/ja.json
@@ -386,6 +386,7 @@
"File name": "ファイル名",
"File permissions": "ファイルの権限",
"Document": "文書",
+ "Diagram": "図",
"Spreadsheet": "スプレッドシート",
"Presentation": "プレゼンテーション",
"Text": "テキスト",
diff --git a/frontend/src/i18n/ko.json b/frontend/src/i18n/ko.json
index c05d55dc..a8efbfda 100644
--- a/frontend/src/i18n/ko.json
+++ b/frontend/src/i18n/ko.json
@@ -386,6 +386,7 @@
"File name": "파일 이름",
"File permissions": "파일 권한",
"Document": "문서",
+ "Diagram": "다이어그램",
"Spreadsheet": "스프레드시트",
"Presentation": "프레젠테이션",
"Text": "텍스트",
diff --git a/frontend/src/i18n/nl.json b/frontend/src/i18n/nl.json
index e0a658c4..90d53934 100644
--- a/frontend/src/i18n/nl.json
+++ b/frontend/src/i18n/nl.json
@@ -386,6 +386,7 @@
"File name": "Bestandsnaam",
"File permissions": "Bestandsmachtigingen",
"Document": "Document",
+ "Diagram": "Diagram",
"Spreadsheet": "Spreadsheet",
"Presentation": "Presentatie",
"Text": "Tekst",
diff --git a/frontend/src/i18n/pl.json b/frontend/src/i18n/pl.json
index d8947ff5..5b3a6817 100644
--- a/frontend/src/i18n/pl.json
+++ b/frontend/src/i18n/pl.json
@@ -386,6 +386,7 @@
"File name": "Nazwa pliku",
"File permissions": "Uprawnienia do pliku",
"Document": "Dokument",
+ "Diagram": "Diagram",
"Spreadsheet": "Arkusz kalkulacyjny",
"Presentation": "Prezentacja",
"Text": "Tekst",
diff --git a/frontend/src/i18n/pt-BR.json b/frontend/src/i18n/pt-BR.json
index 92d2691e..f05de8a8 100644
--- a/frontend/src/i18n/pt-BR.json
+++ b/frontend/src/i18n/pt-BR.json
@@ -386,6 +386,7 @@
"File name": "Nome do arquivo",
"File permissions": "Permissões do arquivo",
"Document": "Documento",
+ "Diagram": "Diagrama",
"Spreadsheet": "Planilha",
"Presentation": "Apresentação",
"Text": "Texto",
diff --git a/frontend/src/i18n/pt.json b/frontend/src/i18n/pt.json
index 45b6c475..1a57d9d3 100644
--- a/frontend/src/i18n/pt.json
+++ b/frontend/src/i18n/pt.json
@@ -386,6 +386,7 @@
"File name": "Nome do arquivo",
"File permissions": "Permissões do arquivo",
"Document": "Documento",
+ "Diagram": "Diagrama",
"Spreadsheet": "Folha de cálculo",
"Presentation": "Apresentação",
"Text": "Texto",
diff --git a/frontend/src/i18n/ru.json b/frontend/src/i18n/ru.json
index 18d04e46..bf619c91 100644
--- a/frontend/src/i18n/ru.json
+++ b/frontend/src/i18n/ru.json
@@ -386,6 +386,7 @@
"File name": "Имя файла",
"File permissions": "Права доступа к файлу",
"Document": "Документ",
+ "Diagram": "Диаграмма",
"Spreadsheet": "Электронная таблица",
"Presentation": "Презентация",
"Text": "Текст",
diff --git a/frontend/src/i18n/tr.json b/frontend/src/i18n/tr.json
index a932e16a..01c29f8b 100644
--- a/frontend/src/i18n/tr.json
+++ b/frontend/src/i18n/tr.json
@@ -386,6 +386,7 @@
"File name": "Dosya adı",
"File permissions": "Dosya izinleri",
"Document": "Belge",
+ "Diagram": "Diyagram",
"Spreadsheet": "Elektronik tablo",
"Presentation": "Sunum",
"Text": "Metin",
diff --git a/frontend/src/i18n/zh.json b/frontend/src/i18n/zh.json
index fef8bf7c..9aff4102 100644
--- a/frontend/src/i18n/zh.json
+++ b/frontend/src/i18n/zh.json
@@ -386,6 +386,7 @@
"File name": "文件名称",
"File permissions": "文件权限",
"Document": "文档",
+ "Diagram": "图表",
"Spreadsheet": "电子表格",
"Presentation": "演示文稿",
"Text": "文本",