Skip to content

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

refactor(files): unify extension handling for OnlyOffice and Collabora integration, enhance file MIME detection

johavenbfd62c109f4a
diff --git a/backend/src/applications/files/modules/collabora-online/collabora-online-manager.service.ts b/backend/src/applications/files/modules/collabora-online/collabora-online-manager.service.ts
index 54db5c2e..c1d774ec 100644
--- a/backend/src/applications/files/modules/collabora-online/collabora-online-manager.service.ts
+++ b/backend/src/applications/files/modules/collabora-online/collabora-online-manager.service.ts
@@ -38,7 +38,7 @@ import {
COLLABORA_HEADERS,
COLLABORA_INTERNAL_URI,
COLLABORA_LOCK_ACTION,
- COLLABORA_ONLINE_SUPPORTED_EXTENSIONS,
+ COLLABORA_ONLINE_EXTENSIONS,
COLLABORA_OWNER_LOCK,
COLLABORA_TOKEN_QUERY_PARAM_NAME,
COLLABORA_URI,
@@ -63,12 +63,12 @@ export class CollaboraOnlineManager {
async getSettings(user: UserModel, space: SpaceEnv): Promise<CollaboraOnlineReqDto> {
await this.checkSpace(space)
const fileExtension = path.extname(space.realPath).slice(1)
- if (!COLLABORA_ONLINE_SUPPORTED_EXTENSIONS.has(fileExtension)) {
+ if (!COLLABORA_ONLINE_EXTENSIONS.has(fileExtension)) {
throw new HttpException('Document not supported', HttpStatus.BAD_REQUEST)
}
const mode: FILE_MODE = haveSpaceEnvPermissions(space, SPACE_OPERATION.MODIFY) ? FILE_MODE.EDIT : FILE_MODE.VIEW
if (mode === FILE_MODE.EDIT) {
- // check lock conflicts
+ // Check lock conflicts
try {
await this.filesLockManager.checkConflicts(space.dbFile, DEPTH.RESOURCE, { userId: user.id, lockScope: LOCK_SCOPE.SHARED })
} catch {
diff --git a/backend/src/applications/files/modules/collabora-online/collabora-online.constants.ts b/backend/src/applications/files/modules/collabora-online/collabora-online.constants.ts
index dd950e10..0c6811c5 100644
--- a/backend/src/applications/files/modules/collabora-online/collabora-online.constants.ts
+++ b/backend/src/applications/files/modules/collabora-online/collabora-online.constants.ts
@@ -24,7 +24,7 @@ export enum COLLABORA_LOCK_ACTION {
REFRESH_LOCK = 'REFRESH_LOCK'
}
-export const COLLABORA_ONLINE_SUPPORTED_EXTENSIONS = new Set<string>([
+export const COLLABORA_ONLINE_EXTENSIONS = new Set<string>([
// ─────────────
// WORD (Writer)
// ─────────────
@@ -37,11 +37,12 @@ export const COLLABORA_ONLINE_SUPPORTED_EXTENSIONS = new Set<string>([
'odt',
'ott',
'rtf',
- 'txt',
- 'html',
- 'htm',
'fodt',
+ // StarOffice / legacy
+ 'sxw',
+ 'stw',
+
// ─────────────
// CELL (Calc)
// ─────────────
@@ -55,6 +56,10 @@ export const COLLABORA_ONLINE_SUPPORTED_EXTENSIONS = new Set<string>([
'csv',
'fods',
+ // StarOffice
+ 'sxc',
+ 'sdc',
+
// ─────────────
// SLIDE (Impress)
// ─────────────
@@ -67,8 +72,12 @@ export const COLLABORA_ONLINE_SUPPORTED_EXTENSIONS = new Set<string>([
'otp',
'fodp',
+ // StarOffice
+ 'sxi',
+ 'sdd',
+
// ─────────────
- // PDF (view / annotations)
+ // DRAW / DIAGRAM
// ─────────────
- 'pdf'
+ 'odg'
])
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 32bfb16f..66d25a8e 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
@@ -78,13 +78,12 @@ export class OnlyOfficeManager {
throw new HttpException('Document must be a file', HttpStatus.BAD_REQUEST)
}
const fileExtension = path.extname(space.realPath).slice(1)
- if (!ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(fileExtension) && !ONLY_OFFICE_EXTENSIONS.EDITABLE.has(fileExtension)) {
+ if (!ONLY_OFFICE_EXTENSIONS.has(fileExtension)) {
throw new HttpException('Document not supported', HttpStatus.BAD_REQUEST)
}
- const mode: FILE_MODE =
- ONLY_OFFICE_EXTENSIONS.EDITABLE.has(fileExtension) && haveSpaceEnvPermissions(space, SPACE_OPERATION.MODIFY) ? FILE_MODE.EDIT : FILE_MODE.VIEW
+ const mode: FILE_MODE = haveSpaceEnvPermissions(space, SPACE_OPERATION.MODIFY) ? FILE_MODE.EDIT : FILE_MODE.VIEW
if (mode === FILE_MODE.EDIT) {
- // check lock conflicts
+ // Check lock conflicts
try {
await this.filesLockManager.checkConflicts(space.dbFile, DEPTH.RESOURCE, { userId: user.id, lockScope: LOCK_SCOPE.SHARED })
} catch {
@@ -154,7 +153,7 @@ export class OnlyOfficeManager {
callBackUrl: string,
isMobile: boolean
): Promise<OnlyOfficeReqDto> {
- const documentType = ONLY_OFFICE_EXTENSIONS.EDITABLE.get(fileExtension) || ONLY_OFFICE_EXTENSIONS.VIEWABLE.get(fileExtension)
+ const documentType = ONLY_OFFICE_EXTENSIONS.get(fileExtension)
return {
documentServerUrl: this.externalOnlyOfficeServer || `${this.contextManager.headerOriginUrl()}${ONLY_OFFICE_INTERNAL_URI}`,
config: {
diff --git a/backend/src/applications/files/modules/only-office/only-office.constants.ts b/backend/src/applications/files/modules/only-office/only-office.constants.ts
index b7422610..83d0c76f 100644
--- a/backend/src/applications/files/modules/only-office/only-office.constants.ts
+++ b/backend/src/applications/files/modules/only-office/only-office.constants.ts
@@ -10,128 +10,95 @@ export const ONLY_OFFICE_TOKEN_QUERY_PARAM_NAME = 'token' as const
export const ONLY_OFFICE_OWNER_LOCK = 'OnlyOffice' as const
export const ONLY_OFFICE_CACHE_KEY = 'foffice' as const
-export const ONLY_OFFICE_EXTENSIONS = {
- VIEWABLE: new Map<string, 'word' | 'cell' | 'slide' | 'pdf' | 'diagram'>([
- // WORD
- ['doc', 'word'],
- ['docm', 'word'],
- ['docx', 'word'],
- ['dot', 'word'],
- ['dotm', 'word'],
- ['dotx', 'word'],
- ['epub', 'word'],
- ['fb2', 'word'],
- ['fodt', 'word'],
- ['gdoc', 'word'],
- ['htm', 'word'],
- ['html', 'word'],
- ['hwp', 'word'],
- ['hwpx', 'word'],
- ['mht', 'word'],
- ['mhtml', 'word'],
- ['odt', 'word'],
- ['ott', 'word'],
- ['pages', 'word'],
- ['rtf', 'word'],
- ['stw', 'word'],
- ['sxw', 'word'],
- ['wps', 'word'],
- ['wpt', 'word'],
+export const ONLY_OFFICE_EXTENSIONS = new Map<string, 'word' | 'cell' | 'slide' | 'pdf' | 'diagram'>([
+ // ─────────────
+ // WORD
+ // ─────────────
+ ['doc', 'word'],
+ ['docm', 'word'],
+ ['docx', 'word'],
+ ['dot', 'word'],
+ ['dotm', 'word'],
+ ['dotx', 'word'],
+ ['epub', 'word'],
+ ['fb2', 'word'],
+ ['fodt', 'word'],
+ ['gdoc', 'word'],
+ ['hwp', 'word'],
+ ['hwpx', 'word'],
+ ['mht', 'word'],
+ ['mhtml', 'word'],
+ ['odt', 'word'],
+ ['ott', 'word'],
+ ['pages', 'word'],
+ ['rtf', 'word'],
+ ['stw', 'word'],
+ ['sxw', 'word'],
+ ['wps', 'word'],
+ ['wpt', 'word'],
- // CELL
- ['csv', 'cell'],
- ['et', 'cell'],
- ['ett', 'cell'],
- ['fods', 'cell'],
- ['gsheet', 'cell'],
- ['numbers', 'cell'],
- ['ods', 'cell'],
- ['ots', 'cell'],
- ['sxc', 'cell'],
- ['xls', 'cell'],
- ['xlsm', 'cell'],
- ['xlsx', 'cell'],
- ['xlt', 'cell'],
- ['xltm', 'cell'],
- ['xltx', 'cell'],
+ // ─────────────
+ // CELL
+ // ─────────────
+ ['csv', 'cell'],
+ ['et', 'cell'],
+ ['ett', 'cell'],
+ ['fods', 'cell'],
+ ['gsheet', 'cell'],
+ ['numbers', 'cell'],
+ ['ods', 'cell'],
+ ['ots', 'cell'],
+ ['sxc', 'cell'],
+ ['xls', 'cell'],
+ ['xlsb', 'cell'],
+ ['xlsm', 'cell'],
+ ['xlsx', 'cell'],
+ ['xlt', 'cell'],
+ ['xltm', 'cell'],
+ ['xltx', 'cell'],
- // SLIDE
- ['dps', 'slide'],
- ['dpt', 'slide'],
- ['fodp', 'slide'],
- ['gslide', 'slide'],
- ['key', 'slide'],
- ['odg', 'slide'],
- ['odp', 'slide'],
- ['otp', 'slide'],
- ['pot', 'slide'],
- ['potm', 'slide'],
- ['potx', 'slide'],
- ['pps', 'slide'],
- ['ppsm', 'slide'],
- ['ppsx', 'slide'],
- ['ppt', 'slide'],
- ['pptm', 'slide'],
- ['pptx', 'slide'],
- ['sxi', 'slide'],
+ // ─────────────
+ // SLIDE
+ // ─────────────
+ ['dps', 'slide'],
+ ['dpt', 'slide'],
+ ['fodp', 'slide'],
+ ['gslide', 'slide'],
+ ['key', 'slide'],
+ ['odg', 'slide'],
+ ['odp', 'slide'],
+ ['otp', 'slide'],
+ ['pot', 'slide'],
+ ['potm', 'slide'],
+ ['potx', 'slide'],
+ ['pps', 'slide'],
+ ['ppsm', 'slide'],
+ ['ppsx', 'slide'],
+ ['ppt', 'slide'],
+ ['pptm', 'slide'],
+ ['pptx', 'slide'],
+ ['sxi', 'slide'],
- // PDF
- ['djvu', 'pdf'],
- ['docxf', 'pdf'],
- ['oform', 'pdf'],
- ['oxps', 'pdf'],
- ['pdf', 'pdf'],
- ['xps', 'pdf'],
+ // ─────────────
+ // PDF
+ // ─────────────
+ ['djvu', 'pdf'],
+ ['docxf', 'pdf'],
+ ['oform', 'pdf'],
+ ['oxps', 'pdf'],
+ ['pdf', 'pdf'],
+ ['xps', 'pdf'],
- // DIAGRAM
- ['vsdm', 'diagram'],
- ['vsdx', 'diagram'],
- ['vssm', 'diagram'],
- ['vssx', 'diagram'],
- ['vstm', 'diagram'],
- ['vstx', 'diagram']
- ]),
-
- EDITABLE: new Map<string, 'word' | 'cell' | 'slide' | 'pdf'>([
- // WORD
- ['doc', 'word'],
- ['docm', 'word'],
- ['docx', 'word'],
- ['dotm', 'word'],
- ['dotx', 'word'],
- ['epub', 'word'],
- ['fb2', 'word'],
- ['html', 'word'],
- ['odt', 'word'],
- ['ott', 'word'],
- ['rtf', 'word'],
-
- // CELL
- ['xlsb', 'cell'],
- ['xlsm', 'cell'],
- ['xls', 'cell'],
- ['xlsx', 'cell'],
- ['xltm', 'cell'],
- ['xltx', 'cell'],
- ['csv', 'cell'],
- ['ods', 'cell'],
- ['ots', 'cell'],
-
- // SLIDE
- ['potm', 'slide'],
- ['potx', 'slide'],
- ['ppsm', 'slide'],
- ['ppsx', 'slide'],
- ['pptm', 'slide'],
- ['ppt', 'slide'],
- ['pptx', 'slide'],
- ['odp', 'slide'],
- ['otp', 'slide'],
-
- // PDF
- ['pdf', 'pdf']
- ])
-}
+ // ─────────────
+ // DIAGRAM
+ // ─────────────
+ ['vsdm', 'diagram'],
+ ['vsdx', 'diagram'],
+ ['vssm', 'diagram'],
+ ['vssx', 'diagram'],
+ ['vstm', 'diagram'],
+ ['vstx', 'diagram']
+])
export const ONLY_OFFICE_CONVERT_EXTENSIONS = {
ALLOW_AUTO: new Set(['doc', 'xls', 'ppt']),
diff --git a/backend/src/applications/files/modules/only-office/only-office.controller.spec.ts b/backend/src/applications/files/modules/only-office/only-office.controller.spec.ts
index d07b104b..a419e9ee 100644
--- a/backend/src/applications/files/modules/only-office/only-office.controller.spec.ts
+++ b/backend/src/applications/files/modules/only-office/only-office.controller.spec.ts
@@ -53,10 +53,10 @@ describe(OnlyOfficeController.name, () => {
const expected = { config: 'ok', mode: FILE_MODE.VIEW }
filesOnlyOfficeManagerMock.getSettings.mockResolvedValue(expected)
- const result = await controller.onlyOfficeSettings(undefined as any, req)
+ const result = await controller.onlyOfficeSettings(req)
expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledTimes(1)
- expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, FILE_MODE.VIEW, req)
+ expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, req)
expect(result).toBe(expected)
})
@@ -67,9 +67,9 @@ describe(OnlyOfficeController.name, () => {
const expected = { config: 'ok', mode: FILE_MODE.EDIT }
filesOnlyOfficeManagerMock.getSettings.mockResolvedValue(expected)
- const result = await controller.onlyOfficeSettings(FILE_MODE.EDIT, req)
+ const result = await controller.onlyOfficeSettings(req)
- expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, FILE_MODE.EDIT, req)
+ expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, req)
expect(result).toBe(expected)
})
})
diff --git a/backend/src/configuration/config.interfaces.ts b/backend/src/configuration/config.interfaces.ts
index 53d65bf4..875e26f9 100644
--- a/backend/src/configuration/config.interfaces.ts
+++ b/backend/src/configuration/config.interfaces.ts
@@ -4,8 +4,13 @@
* See the LICENSE file for licensing details
*/
+export interface EditorConfig {
+ collaboraOnline: boolean
+ onlyOffice: boolean
+}
+
export interface ServerConfig {
twoFaEnabled: boolean
mailServerEnabled: boolean
- applications: { files: { collaboraOnline: boolean; onlyOffice: boolean } }
+ applications: { files: EditorConfig }
}
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 a2d984ef..a8008c2e 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
@@ -104,7 +104,6 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
private readonly filesServices = inject(FilesService)
private readonly filesUpload = inject(FilesUploadService)
private subscription = this.layout.switchTheme.subscribe((layout: string) => (this.currentTheme = layout === themeDark ? 'dark' : 'light'))
- private readonly maxSize = 5242880 // 5MB
constructor() {
effect(() => {
@@ -173,15 +172,9 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
async ngOnInit() {
const language: LanguageDescription = LanguageDescription.matchFilename(languages, this.file().name)
- if (language?.name || this.file().size <= this.maxSize) {
- this.currentLanguage = language?.name
- this.isSupported.set(true)
- this.loadContent().catch(console.error)
- } else {
- this.isReadonly.set(true)
- this.isSupported.set(false)
- this.content = this.layout.translateString('This file contains binary data that can not be read')
- }
+ this.currentLanguage = language?.name
+ this.isSupported.set(true)
+ this.loadContent().catch(console.error)
}
async toggleReadonly() {
diff --git a/frontend/src/app/applications/files/files.constants.ts b/frontend/src/app/applications/files/files.constants.ts
index a4af4458..0709fc73 100644
--- a/frontend/src/app/applications/files/files.constants.ts
+++ b/frontend/src/app/applications/files/files.constants.ts
@@ -23,6 +23,7 @@ export const logoDarkUrl = `${assetsUrl}/logo-dark${mimeExtension}`
export const logoUrl = `${assetsUrl}/logo${mimeExtension}`
export const linkProtected = `${assetsUrl}/protected.png`
export const defaultMimeUrl = getAssetsMimeUrl(mimeFile)
+export const MAX_TEXT_FILE_SIZE = 10485760 // 10 MB
export const COMPRESSIBLE_MIMES = new Set(['application-gzip', 'application-zip', 'application-x-tar'])
export const SHORT_MIME = {
DOCUMENT: 'document',
diff --git a/frontend/src/app/applications/files/models/file.model.ts b/frontend/src/app/applications/files/models/file.model.ts
index 26d63741..3306d8b0 100644
--- a/frontend/src/app/applications/files/models/file.model.ts
+++ b/frontend/src/app/applications/files/models/file.model.ts
@@ -10,10 +10,12 @@ import {
API_FILES_TASK_OPERATION
} from '@sync-in-server/backend/src/applications/files/constants/routes'
import type { FileLockProps, FileProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'
+import { COLLABORA_ONLINE_EXTENSIONS } from '@sync-in-server/backend/src/applications/files/modules/collabora-online/collabora-online.constants'
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 { EditorConfig } from '@sync-in-server/backend/src/configuration/config.interfaces'
import type { Observable } from 'rxjs'
import { convertBytesToText, getNewly } from '../../../common/utils/functions'
import { dJs } from '../../../common/utils/time'
@@ -87,11 +89,11 @@ export class FileModel implements File {
canBeReShared = false
haveThumbnail = false
- constructor(props: FileProps | File, basePath: string, inShare = false) {
+ constructor(props: FileProps | File, basePath: string, inShare = false, editorConfig: EditorConfig) {
this.setShares(popFromObject('shares', props))
Object.assign(this, props)
this.path = `${basePath}/${this.path !== '.' ? `${this.path}/` : ''}${this.root?.alias || this.name}`
- this.mime = this.getMime(this.mime, inShare)
+ this.mime = this.getMime(this.mime, inShare, editorConfig)
this.updateHTimeAgo(this.mtime)
this.setMimeUrl()
this.setHSize()
@@ -138,52 +140,80 @@ export class FileModel implements File {
this.lock = null
}
- private getType(inShare: boolean) {
+ private getType(inShare: boolean): 'directory_share' | 'directory' | 'file' {
return this.isDir ? (inShare ? mimeDirectoryShare : mimeDirectory) : mimeFile
}
- private getMime(mime: string, inShare: boolean) {
+ private getMime(mime: string, inShare: boolean, editorConfig: EditorConfig): string {
if (this.isDir) {
this.isViewable = false
return this.getType(inShare)
- } else if (mime) {
- const temporaryMime = mime.split('-')[0]
- const extension = this.name.split('.').pop().toLowerCase()
- if (extension === SHORT_MIME.PDF) {
- this.shortMime = SHORT_MIME.PDF
- this.isViewable = true
- this.isEditable = ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension)
- } else if (ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension) || ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(extension)) {
- this.shortMime = SHORT_MIME.DOCUMENT
- this.isEditable = ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension)
- this.isViewable = this.isEditable || ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(extension)
- } else if (extension === 'mp4') {
- this.isViewable = true
- this.shortMime = SHORT_MIME.MEDIA
- this.haveThumbnail = true
- } else if (temporaryMime === SHORT_MIME.IMAGE) {
- this.shortMime = SHORT_MIME.IMAGE
- this.isImage = true
- this.isViewable = true
- this.haveThumbnail = true
- } else if (['video', 'audio'].indexOf(temporaryMime) > -1) {
- this.shortMime = SHORT_MIME.MEDIA
- this.isViewable = true
- this.haveThumbnail = true
- } else if (COMPRESSIBLE_MIMES.has(mime)) {
- this.isCompressible = false
- this.isViewable = false
- } else if (!UNSUPPORTED_VIEW_EXTENSIONS.has(extension)) {
- this.isViewable = true
- this.isEditable = true
- this.shortMime = SHORT_MIME.TEXT
- }
- return mime
- } else {
+ }
+
+ if (!mime || mime === mimeFile) {
this.isViewable = true
this.shortMime = SHORT_MIME.TEXT
return this.getType(inShare)
}
+
+ const dot = this.name.lastIndexOf('.')
+ const extension = dot >= 0 ? this.name.slice(dot + 1).toLowerCase() : ''
+ const dash = mime.indexOf('-')
+ const temporaryMime = dash >= 0 ? mime.slice(0, dash) : mime
+
+ if (extension === SHORT_MIME.PDF) {
+ this.shortMime = SHORT_MIME.PDF
+ this.isViewable = true
+ this.isEditable = editorConfig.onlyOffice === true
+ return mime
+ }
+
+ if (
+ (editorConfig.collaboraOnline === true && COLLABORA_ONLINE_EXTENSIONS.has(extension)) ||
+ (editorConfig.onlyOffice === true && ONLY_OFFICE_EXTENSIONS.has(extension))
+ ) {
+ this.shortMime = SHORT_MIME.DOCUMENT
+ this.isEditable = true
+ this.isViewable = true
+ return mime
+ }
+
+ if (extension === 'mp4') {
+ this.isViewable = true
+ this.shortMime = SHORT_MIME.MEDIA
+ this.haveThumbnail = true
+ return mime
+ }
+
+ if (temporaryMime === SHORT_MIME.IMAGE) {
+ this.shortMime = SHORT_MIME.IMAGE
+ this.isImage = true
+ this.isViewable = true
+ this.haveThumbnail = true
+ return mime
+ }
+
+ if (temporaryMime === 'video' || temporaryMime === 'audio') {
+ this.shortMime = SHORT_MIME.MEDIA
+ this.isViewable = true
+ this.haveThumbnail = true
+ return mime
+ }
+
+ if (COMPRESSIBLE_MIMES.has(mime)) {
+ this.isCompressible = false
+ this.isViewable = false
+ return mime
+ }
+
+ if (!UNSUPPORTED_VIEW_EXTENSIONS.has(extension)) {
+ this.shortMime = SHORT_MIME.TEXT
+ this.isViewable = true
+ this.isEditable = true
+ return mime
+ }
+
+ return mime
}
private setMimeUrl() {
diff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.ts
index 478690e5..11599bb9 100644
--- a/frontend/src/app/applications/files/services/files.service.ts
+++ b/frontend/src/app/applications/files/services/files.service.ts
@@ -43,7 +43,7 @@ import { StoreService } from '../../../store/store.service'
import { FilesLockDialogComponent } from '../components/dialogs/files-lock-dialog.component'
import { FilesOverwriteDialogComponent } from '../components/dialogs/files-overwrite-dialog.component'
import { FilesViewerDialogComponent } from '../components/dialogs/files-viewer-dialog.component'
-import { SHORT_MIME } from '../files.constants'
+import { MAX_TEXT_FILE_SIZE, SHORT_MIME } from '../files.constants'
import { FileContentModel } from '../models/file-content.model'
import { FileRecentModel } from '../models/file-recent.model'
import { FileModel } from '../models/file.model'
@@ -266,7 +266,7 @@ export class FilesService {
let hookedShortMime: string
try {
- hookedShortMime = await this.viewerHook(mode, file)
+ hookedShortMime = await this.viewerHook(file, isWriteable)
if (isLockedByOther) {
this.layout.sendNotification('info', 'The file is locked', file.lock.owner)
}
@@ -293,20 +293,17 @@ export class FilesService {
})
}
- private async viewerHook(mode: FILE_MODE, file: FileModel): Promise<string> {
- const hasEnabledOfficeEditor =
- this.store.server().applications.files.collaboraOnline || this.store.server().applications.files.onlyOffice || false
- if (file.shortMime === SHORT_MIME.DOCUMENT && !hasEnabledOfficeEditor) {
- if (file.mime.startsWith('text-')) {
+ private async viewerHook(file: FileModel, isWriteable = false): Promise<string> {
+ if (isWriteable && file.shortMime === SHORT_MIME.PDF && file.isEditable) {
+ return SHORT_MIME.DOCUMENT
+ }
+ if (file.shortMime === SHORT_MIME.TEXT) {
+ if (file.size < MAX_TEXT_FILE_SIZE) {
return SHORT_MIME.TEXT
}
+ // Download if too large
throw new Error('No editor found')
}
- if (file.shortMime === SHORT_MIME.PDF) {
- if (mode === FILE_MODE.EDIT && this.store.server().applications.files.onlyOffice) {
- return SHORT_MIME.DOCUMENT
- }
- }
return file.shortMime
}
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 d49498bf..c30541c7 100644
--- a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
+++ b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
@@ -342,7 +342,7 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
this.sortBy(
this.sortTable.sortParam.column,
false,
- spacesFiles.files.map((f: FileProps) => new FileModel(f, this.baseRepoUrl, this.isSharesRepo))
+ spacesFiles.files.map((f: FileProps) => new FileModel(f, this.baseRepoUrl, this.isSharesRepo, this.store.server().applications.files))
)
this.updateFilesStats(this.files)
this.loading = false