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(frontend:files): improve markdown detection and viewer handling
johaven3d2d871d9bef
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.htmlindex fe4ae4c2..6da12ea3 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@@ -27,34 +27,37 @@@case (SHORT_MIME.DOCUMENT) {<!-- PDF toggled to OnlyOffice: editorProvider flags are not set for PDFs, so we route directly when the original file was a PDF (hookedShortMime === SHORT_MIME.PDF) -->@if (hookedShortMime === SHORT_MIME.PDF) {- <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile" [(isReadonly)]="isReadonly"></app-files-viewer-only-office>+ <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile"+ [(isReadonly)]="isReadonly"></app-files-viewer-only-office>} @else if (editorProvider.collabora) {- <app-files-viewer-collabora-online [currentHeight]="currentHeight" [file]="currentFile" [(isReadonly)]="isReadonly"></app-files-viewer-collabora-online>+ <app-files-viewer-collabora-online [currentHeight]="currentHeight" [file]="currentFile"+ [(isReadonly)]="isReadonly"></app-files-viewer-collabora-online>} @else if (editorProvider.onlyoffice) {- <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile" [(isReadonly)]="isReadonly"></app-files-viewer-only-office>+ <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile"+ [(isReadonly)]="isReadonly"></app-files-viewer-only-office>} @else {<!--This case should never happen--><div [style.height.px]="currentHeight" class="d-flex p-4" l10nTranslate>No editor found</div>}}+ @case (SHORT_MIME.MARKDOWN) {+ <app-files-viewer-markdown+ [currentHeight]="currentHeight"+ [file]="currentFile"+ [isWriteable]="isWriteable"+ [modalClosing]="modalClosing()"+ [(isReadonly)]="isReadonly">+ </app-files-viewer-markdown>+ }@default {- @if (isMarkdownFile) {- <app-files-viewer-markdown- [currentHeight]="currentHeight"- [file]="currentFile"- [isWriteable]="isWriteable"- [modalClosing]="modalClosing()"- [(isReadonly)]="isReadonly">- </app-files-viewer-markdown>- } @else {- <app-files-viewer-text- [currentHeight]="currentHeight"- [file]="currentFile"- [isWriteable]="isWriteable"- [modalClosing]="modalClosing()"- [(isReadonly)]="isReadonly">- </app-files-viewer-text>- }+ <app-files-viewer-text+ [currentHeight]="currentHeight"+ [file]="currentFile"+ [isWriteable]="isWriteable"+ [modalClosing]="modalClosing()"+ [(isReadonly)]="isReadonly">+ </app-files-viewer-text>+}}</div>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.tsindex 0978339f..49e676e8 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@@ -47,17 +47,12 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {protected readonly icons = { faEye, faPen }protected directoryImages = computed(() => this.directoryFiles.filter((file) => file.isImage))protected canToggleViewer = false- protected readonly markdownExtensions = new Set(['md', 'markdown', 'mdown', 'mkd', 'mkdn'])protected readonly store = inject(StoreService)private openedFile: { id: string | number; name: string; mimeUrl: string }private readonly layout = inject(LayoutService)private readonly subscription: Subscription = this.layout.resizeEvent.subscribe(() => this.onResize())private readonly offsetTop = 42- protected get isMarkdownFile(): boolean {- return this.markdownExtensions.has(this.currentFile?.getExtension())- }-ngOnInit() {this.canToggleViewer = this.isWriteable && !!this.currentFile?.isEditable && this.hookedShortMime === SHORT_MIME.PDFthis.activeViewer.set(this.hookedShortMime)@@ -71,7 +66,7 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {}onClose() {- if (this.currentFile.isEditable && this.hookedShortMime === SHORT_MIME.TEXT) {+ if (this.currentFile.isEditable && (this.hookedShortMime === SHORT_MIME.TEXT || this.hookedShortMime === SHORT_MIME.MARKDOWN)) {// Prevent closing the modal without saving when using text-based editorsthis.modalClosing.set(true)// Force the next state changediff --git a/frontend/src/app/applications/files/files.constants.ts b/frontend/src/app/applications/files/files.constants.tsindex b8deae01..71d3c6b0 100644--- a/frontend/src/app/applications/files/files.constants.ts+++ b/frontend/src/app/applications/files/files.constants.ts@@ -22,6 +22,7 @@ export const COMPRESSIBLE_MIMES = new Set(['application-gzip', 'application-zip'export const SHORT_MIME = {DOCUMENT: 'document',TEXT: 'text',+ MARKDOWN: 'markdown',IMAGE: 'image',MEDIA: 'media',PDF: 'pdf'diff --git a/frontend/src/app/applications/files/models/file.model.ts b/frontend/src/app/applications/files/models/file.model.tsindex dee22a04..c563e957 100644--- a/frontend/src/app/applications/files/models/file.model.ts+++ b/frontend/src/app/applications/files/models/file.model.ts@@ -173,6 +173,13 @@ export class FileModel implements File {return this.getType(inShare)}+ if (mime.includes(SHORT_MIME.MARKDOWN)) {+ this.shortMime = SHORT_MIME.MARKDOWN+ this.isViewable = true+ this.isEditable = true+ return mime+ }+const extension = this.getExtension()const dash = mime.indexOf('-')const temporaryMime = dash >= 0 ? mime.slice(0, dash) : mimediff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.tsindex 16edfc2d..7965e979 100644--- a/frontend/src/app/applications/files/services/files.service.ts+++ b/frontend/src/app/applications/files/services/files.service.ts@@ -359,9 +359,9 @@ export class FilesService {}private async viewerHook(file: FileModel): Promise<string> {- if (file.shortMime === SHORT_MIME.TEXT) {+ if (file.shortMime === SHORT_MIME.TEXT || file.shortMime === SHORT_MIME.MARKDOWN) {if (file.size < MAX_TEXT_FILE_SIZE) {- return SHORT_MIME.TEXT+ return file.shortMime}// Download if too largethrow new Error('No editor found')