Browse Source

fix file size getter (#659)

keef3ar 1 year ago
parent
commit
0cf5f0ff6a
2 changed files with 5 additions and 2 deletions
  1. 4 1
      gramjs/Utils.ts
  2. 1 1
      gramjs/tl/custom/file.ts

+ 4 - 1
gramjs/Utils.ts

@@ -236,7 +236,10 @@ export function _photoSizeByteCount(size: Api.TypePhotoSize) {
         return size.bytes.length;
     } else if (size instanceof Api.PhotoSizeEmpty) {
         return 0;
-    } else {
+    } else if (size instanceof Api.PhotoSizeProgressive) {
+        return size.sizes[size.sizes.length -1];
+    }
+    else {
         return undefined;
     }
 }

+ 1 - 1
gramjs/tl/custom/file.ts

@@ -69,7 +69,7 @@ export class File {
 
     get size() {
         if (this.media instanceof Api.Photo) {
-            return _photoSizeByteCount(this.media.sizes[-1]);
+            return _photoSizeByteCount(this.media.sizes[this.media.sizes.length -1]);
         } else if (this.media instanceof Api.Document) {
             return this.media.size;
         }