Add maxSizeAutoDownloads with default set to 10Mb

This commit is contained in:
N-Pex 2023-12-04 15:28:03 +01:00
parent 324ccd70b3
commit db517fbd9c
9 changed files with 12 additions and 8 deletions

View file

@ -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. * **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". * **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". * **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: ### Sticker short codes - To enable sticker short codes, follow these steps:

View file

@ -1507,7 +1507,7 @@ export default {
setReplyToImage(event) { setReplyToImage(event) {
util util
.getThumbnail(this.$matrix.matrixClient, event) .getThumbnail(this.$matrix.matrixClient, event, this.$config)
.then((url) => { .then((url) => {
this.replyToImg = url; this.replyToImg = url;
}) })

View file

@ -39,7 +39,7 @@ export default {
const width = this.$refs.image.$el.clientWidth; const width = this.$refs.image.$el.clientWidth;
const height = (width * 9) / 16; const height = (width * 9) / 16;
util util
.getThumbnail(this.$matrix.matrixClient, this.event, width, height) .getThumbnail(this.$matrix.matrixClient, this.event, this.$config, width, height)
.then((url) => { .then((url) => {
const info = this.event.getContent().info; const info = this.event.getContent().info;
// JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to // JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to

View file

@ -80,7 +80,7 @@ export default {
}; };
ret.promise = ret.promise =
util util
.getThumbnail(this.$matrix.matrixClient, e, 100, 100) .getThumbnail(this.$matrix.matrixClient, e, this.$config, 100, 100)
.then((url) => { .then((url) => {
ret.src = url; ret.src = url;
}) })

View file

@ -38,7 +38,7 @@ export default {
const width = this.$refs.image.$el.clientWidth; const width = this.$refs.image.$el.clientWidth;
const height = (width * 9) / 16; const height = (width * 9) / 16;
util util
.getThumbnail(this.$matrix.matrixClient, this.event, width, height) .getThumbnail(this.$matrix.matrixClient, this.event, this.$config, width, height)
.then((url) => { .then((url) => {
const info = this.event.getContent().info; const info = this.event.getContent().info;
// JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to // JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to

View file

@ -81,7 +81,7 @@ export default {
}; };
ret.promise = ret.promise =
util util
.getThumbnail(this.$matrix.matrixClient, e, 100, 100) .getThumbnail(this.$matrix.matrixClient, e, this.$config, 100, 100)
.then((url) => { .then((url) => {
ret.src = url; ret.src = url;
}) })

View file

@ -39,7 +39,7 @@ export default {
} }
if (event) { if (event) {
const fileSize = util.getFileSize(event); const fileSize = util.getFileSize(event);
if (!userInitiated && (fileSize == 0 || fileSize > 1000000)) { if (!userInitiated && (fileSize == 0 || fileSize > this.$config.maxSizeAutoDownloads)) {
this.userInitiatedDownloadsOnly = true; this.userInitiatedDownloadsOnly = true;
return; return;
} }

View file

@ -130,7 +130,7 @@ class Util {
}); });
} }
getThumbnail(matrixClient, event, ignoredw, ignoredh) { getThumbnail(matrixClient, event, config, ignoredw, ignoredh) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const content = event.getContent(); const content = event.getContent();
if (content.url != null) { if (content.url != null) {
@ -160,7 +160,7 @@ class Util {
// true // true
// ); // );
url = matrixClient.mxcUrlToHttp(file.url); 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 // No thumb, use real url
file = content.file; file = content.file;
url = matrixClient.mxcUrlToHttp(file.url); url = matrixClient.mxcUrlToHttp(file.url);

View file

@ -26,6 +26,9 @@ export default {
if (json.useFullyQualifiedDMLinks == undefined) { if (json.useFullyQualifiedDMLinks == undefined) {
Vue.set(config, "useFullyQualifiedDMLinks", true); // Default to true Vue.set(config, "useFullyQualifiedDMLinks", true); // Default to true
} }
if (!json.maxSizeAutoDownloads) {
Vue.set(config, "maxSizeAutoDownloads", 10 * 1024 * 1024);
}
Vue.set(config, "loaded", true); Vue.set(config, "loaded", true);
// Tell callback we are done loading runtime config // Tell callback we are done loading runtime config