diff --git a/src/public/app/widgets/type_widgets/file.ts b/src/public/app/widgets/type_widgets/file.ts index 8030a7c93..735988278 100644 --- a/src/public/app/widgets/type_widgets/file.ts +++ b/src/public/app/widgets/type_widgets/file.ts @@ -4,6 +4,8 @@ import { t } from "../../services/i18n.js"; import type { EventData } from "../../components/app_context.js"; import type FNote from "../../entities/fnote.js"; +const TEXT_MAX_NUM_CHARS = 5000; + const TPL = `
+
+ ${t("file.too_big", { maxNumChars: TEXT_MAX_NUM_CHARS })} +
+

 
     
@@ -46,6 +52,7 @@ export default class FileTypeWidget extends TypeWidget { private $previewContent!: JQuery; private $previewNotAvailable!: JQuery; + private $previewTooBig!: JQuery; private $pdfPreview!: JQuery; private $videoPreview!: JQuery; private $audioPreview!: JQuery; @@ -58,6 +65,7 @@ export default class FileTypeWidget extends TypeWidget { this.$widget = $(TPL); this.$previewContent = this.$widget.find(".file-preview-content"); this.$previewNotAvailable = this.$widget.find(".file-preview-not-available"); + this.$previewTooBig = this.$widget.find(".file-preview-too-big"); this.$pdfPreview = this.$widget.find(".pdf-preview"); this.$videoPreview = this.$widget.find(".video-preview"); this.$audioPreview = this.$widget.find(".audio-preview"); @@ -73,12 +81,17 @@ export default class FileTypeWidget extends TypeWidget { this.$previewContent.empty().hide(); this.$pdfPreview.attr("src", "").empty().hide(); this.$previewNotAvailable.hide(); + this.$previewTooBig.hide(); this.$videoPreview.hide(); this.$audioPreview.hide(); if (blob?.content) { this.$previewContent.show().scrollTop(0); - this.$previewContent.text(blob.content); + const trimmedContent = blob.content.substring(0, TEXT_MAX_NUM_CHARS); + if (trimmedContent.length !== blob.content.length) { + this.$previewTooBig.show(); + } + this.$previewContent.text(trimmedContent); } else if (note.mime === "application/pdf") { this.$pdfPreview.show().attr("src", openService.getUrlForDownload(`api/notes/${this.noteId}/open`)); } else if (note.mime.startsWith("video/")) { diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.json index 1a5d92b32..ccffe93d5 100644 --- a/src/public/translations/en/translation.json +++ b/src/public/translations/en/translation.json @@ -966,7 +966,8 @@ "enter_workspace": "Enter workspace {{title}}" }, "file": { - "file_preview_not_available": "File preview is not available for this file format." + "file_preview_not_available": "File preview is not available for this file format.", + "too_big": "The preview only shows the first {{maxNumChars}} characters of the file for performance reasons. Download the file and open it externally to be able to see the entire content." }, "protected_session": { "enter_password_instruction": "Showing protected note requires entering your password:",