Procházet zdrojové kódy

Determine correct max file size

This is done using the "capabilities" field in the client info message
sent by the app.
Danilo Bargen před 7 roky
rodič
revize
2812529913
4 změnil soubory, kde provedl 18 přidání a 6 odebrání
  1. 3 1
      public/i18n/de.json
  2. 3 1
      public/i18n/en.json
  3. 11 4
      src/services/webclient.ts
  4. 1 0
      src/threema.d.ts

+ 3 - 1
public/i18n/de.json

@@ -210,7 +210,9 @@
         "FILE_MESSAGES_NOT_SUPPORTED": "«{receiverName}» kann noch keine Dateien erhalten.",
         "CONTACT_BLOCKED":  "Sie können keine Nachrichten an blockierte Kontakte senden.",
         "ERROR_OCCURRED": "Es ist ein Fehler aufgetreten.",
-        "FILE_TOO_LARGE": "Aktuell können keine Dateien grösser als 15 MiB über Threema Web versendet werden",
+        "FILE_TOO_LARGE": "Dateien grösser als {maxmb} MiB können nicht versendet werden",
+        "FILE_TOO_LARGE_WEB": "Aktuell können keine Dateien grösser als 15 MiB über Threema Web versendet werden",
+        "FILE_TOO_LARGE_GENERIC": "Datei kann nicht gesendet werden, weil sie zu gross ist",
         "TEXT_TOO_LONG": "Diese Nachricht ist zu lang und kann nicht gesendet werden (Maximale Länge {max} Zeichen).",
         "NOTIFICATION_PERMISSION_DENIED": "Sie müssen die Benachrichtigungsberechtigung für Threema Web manuell erteilen, um Desktopbenachrichtigungen erhalten zu können.",
         "NOTIFICATION_PERMISSION_DENIED_LEARN_MORE": "Mehr erfahren.",

+ 3 - 1
public/i18n/en.json

@@ -210,7 +210,9 @@
         "FILE_MESSAGES_NOT_SUPPORTED": "«{receiverName}» cannot receive files.",
         "CONTACT_BLOCKED":  "You cannot send messages to a blocked contact.",
         "ERROR_OCCURRED": "An error occurred.",
-        "FILE_TOO_LARGE": "Currently files larger than 15 MiB cannot be sent through Threema Web",
+        "FILE_TOO_LARGE": "Files larger than {maxmb} MiB cannot be sent",
+        "FILE_TOO_LARGE_WEB": "Currently files larger than 15 MiB cannot be sent through Threema Web",
+        "FILE_TOO_LARGE_GENERIC": "File is too large to be sent",
         "TEXT_TOO_LONG": "This message is too long and cannot be sent (Max length {max} characters).",
         "NOTIFICATION_PERMISSION_DENIED": "You have to grant the notification permission for Threema Web manually in order to receive desktop notifications.",
         "NOTIFICATION_PERMISSION_DENIED_LEARN_MORE": "Learn more.",

+ 11 - 4
src/services/webclient.ts

@@ -46,7 +46,7 @@ import ContactReceiverFeature = threema.ContactReceiverFeature;
 export class WebClientService {
     private static AVATAR_LOW_MAX_SIZE = 48;
     private static MAX_TEXT_LENGTH = 3500;
-    private static MAX_FILE_SIZE = 15 * 1024 * 1024;
+    private static MAX_FILE_SIZE_WEBRTC = 15 * 1024 * 1024;
 
     private static TYPE_REQUEST = 'request';
     private static TYPE_RESPONSE = 'response';
@@ -1063,8 +1063,14 @@ export class WebClientService {
                     case 'file':
                         // Validate max file size
                         if (this.chosenTask === threema.ChosenTask.WebRTC) {
-                            if ((message as threema.FileMessageData).size > WebClientService.MAX_FILE_SIZE) {
-                                return reject(this.$translate.instant('error.FILE_TOO_LARGE'));
+                            if ((message as threema.FileMessageData).size > WebClientService.MAX_FILE_SIZE_WEBRTC) {
+                                return reject(this.$translate.instant('error.FILE_TOO_LARGE_WEB'));
+                            }
+                        } else {
+                            if ((message as threema.FileMessageData).size > this.clientInfo.capabilities.maxFileSize) {
+                                return reject(this.$translate.instant('error.FILE_TOO_LARGE', {
+                                    maxmb: Math.floor(this.clientInfo.capabilities.maxFileSize / 1024 / 1024),
+                                }));
                             }
                         }
 
@@ -1156,7 +1162,7 @@ export class WebClientService {
                     let errorMessage;
                     switch (error) {
                         case 'file_too_large':
-                            errorMessage = this.$translate.instant('error.FILE_TOO_LARGE');
+                            errorMessage = this.$translate.instant('error.FILE_TOO_LARGE_GENERIC');
                             break;
                         case 'blocked':
                             errorMessage = this.$translate.instant('error.CONTACT_BLOCKED');
@@ -2254,6 +2260,7 @@ export class WebClientService {
             },
             capabilities: {
                 maxGroupSize: getOrDefault<number>(data.capabilities.maxGroupSize, 50),
+                maxFileSize: getOrDefault<number>(data.capabilities.maxFileSize, 50 * 1024 * 1024),
                 distributionLists: getOrDefault<boolean>(data.capabilities.distributionLists, true),
                 mdm: data.capabilities.mdm,
             },

+ 1 - 0
src/threema.d.ts

@@ -640,6 +640,7 @@ declare namespace threema {
 
     interface AppCapabilities {
         maxGroupSize: number;
+        maxFileSize: number;
         distributionLists: boolean;
         mdm?: MdmRestrictions;
     }