From db517fbd9c2b78c0949a375897fe61cddef2bb74 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Mon, 4 Dec 2023 15:28:03 +0100 Subject: [PATCH] Add maxSizeAutoDownloads with default set to 10Mb --- README.md | 1 + src/components/Chat.vue | 2 +- src/components/messages/MessageIncomingImage.vue | 2 +- src/components/messages/MessageIncomingThread.vue | 2 +- src/components/messages/MessageOutgoingImage.vue | 2 +- src/components/messages/MessageOutgoingThread.vue | 2 +- src/components/messages/attachmentMixin.js | 2 +- src/plugins/utils.js | 4 ++-- src/services/config.service.js | 3 +++ 9 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 72b3262..2292d13 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ The app loads runtime configutation from the server at "./config.json" and merge * **logo** - An url or base64-encoded image data url that represents the app logotype. * **accentColor** - The accent color of the app UI. Use a HTML-style color value string, like "#ff0080". * **show_status_messages** - Whether to show only user joins/leaves and display name updates, or the full range of room status updates. Possible values are "never" (only the above), "moderators" (moderators will see all status updates) or "always" (everyone will see all status updates). Defaults to "always". +* **maxSizeAutoDownloads** - Attachments smaller than this will be auto downloaded. Default is 10Mb. ### Sticker short codes - To enable sticker short codes, follow these steps: diff --git a/src/components/Chat.vue b/src/components/Chat.vue index a34378b..5aa0489 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -1507,7 +1507,7 @@ export default { setReplyToImage(event) { util - .getThumbnail(this.$matrix.matrixClient, event) + .getThumbnail(this.$matrix.matrixClient, event, this.$config) .then((url) => { this.replyToImg = url; }) diff --git a/src/components/messages/MessageIncomingImage.vue b/src/components/messages/MessageIncomingImage.vue index b73752f..732c584 100644 --- a/src/components/messages/MessageIncomingImage.vue +++ b/src/components/messages/MessageIncomingImage.vue @@ -39,7 +39,7 @@ export default { const width = this.$refs.image.$el.clientWidth; const height = (width * 9) / 16; util - .getThumbnail(this.$matrix.matrixClient, this.event, width, height) + .getThumbnail(this.$matrix.matrixClient, this.event, this.$config, width, height) .then((url) => { const info = this.event.getContent().info; // JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to diff --git a/src/components/messages/MessageIncomingThread.vue b/src/components/messages/MessageIncomingThread.vue index 85ffc0e..2bab13b 100644 --- a/src/components/messages/MessageIncomingThread.vue +++ b/src/components/messages/MessageIncomingThread.vue @@ -80,7 +80,7 @@ export default { }; ret.promise = util - .getThumbnail(this.$matrix.matrixClient, e, 100, 100) + .getThumbnail(this.$matrix.matrixClient, e, this.$config, 100, 100) .then((url) => { ret.src = url; }) diff --git a/src/components/messages/MessageOutgoingImage.vue b/src/components/messages/MessageOutgoingImage.vue index e9e5c29..3035c71 100644 --- a/src/components/messages/MessageOutgoingImage.vue +++ b/src/components/messages/MessageOutgoingImage.vue @@ -38,7 +38,7 @@ export default { const width = this.$refs.image.$el.clientWidth; const height = (width * 9) / 16; util - .getThumbnail(this.$matrix.matrixClient, this.event, width, height) + .getThumbnail(this.$matrix.matrixClient, this.event, this.$config, width, height) .then((url) => { const info = this.event.getContent().info; // JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to diff --git a/src/components/messages/MessageOutgoingThread.vue b/src/components/messages/MessageOutgoingThread.vue index ca1cda5..ebcf953 100644 --- a/src/components/messages/MessageOutgoingThread.vue +++ b/src/components/messages/MessageOutgoingThread.vue @@ -81,7 +81,7 @@ export default { }; ret.promise = util - .getThumbnail(this.$matrix.matrixClient, e, 100, 100) + .getThumbnail(this.$matrix.matrixClient, e, this.$config, 100, 100) .then((url) => { ret.src = url; }) diff --git a/src/components/messages/attachmentMixin.js b/src/components/messages/attachmentMixin.js index df6f4af..0fed50b 100644 --- a/src/components/messages/attachmentMixin.js +++ b/src/components/messages/attachmentMixin.js @@ -39,7 +39,7 @@ export default { } if (event) { const fileSize = util.getFileSize(event); - if (!userInitiated && (fileSize == 0 || fileSize > 1000000)) { + if (!userInitiated && (fileSize == 0 || fileSize > this.$config.maxSizeAutoDownloads)) { this.userInitiatedDownloadsOnly = true; return; } diff --git a/src/plugins/utils.js b/src/plugins/utils.js index 5e5d3e4..c1b2057 100644 --- a/src/plugins/utils.js +++ b/src/plugins/utils.js @@ -130,7 +130,7 @@ class Util { }); } - getThumbnail(matrixClient, event, ignoredw, ignoredh) { + getThumbnail(matrixClient, event, config, ignoredw, ignoredh) { return new Promise((resolve, reject) => { const content = event.getContent(); if (content.url != null) { @@ -160,7 +160,7 @@ class Util { // true // ); url = matrixClient.mxcUrlToHttp(file.url); - } else if (content.file && content.file.url && this.getMimeType(event).startsWith("image/")) { + } else if (content.file && content.file.url && this.getFileSize(event) > 0 && this.getFileSize(event) < config.maxSizeAutoDownloads) { // No thumb, use real url file = content.file; url = matrixClient.mxcUrlToHttp(file.url); diff --git a/src/services/config.service.js b/src/services/config.service.js index 56dd7aa..1885a0d 100644 --- a/src/services/config.service.js +++ b/src/services/config.service.js @@ -26,6 +26,9 @@ export default { if (json.useFullyQualifiedDMLinks == undefined) { Vue.set(config, "useFullyQualifiedDMLinks", true); // Default to true } + if (!json.maxSizeAutoDownloads) { + Vue.set(config, "maxSizeAutoDownloads", 10 * 1024 * 1024); + } Vue.set(config, "loaded", true); // Tell callback we are done loading runtime config