Sfoglia il codice sorgente

Use default file size in case of profile pictures.

painor 3 anni fa
parent
commit
2bc89dddb2
5 ha cambiato i file con 19 aggiunte e 15 eliminazioni
  1. 1 1
      gramjs/Version.ts
  2. 15 10
      gramjs/client/downloads.ts
  3. 0 1
      gramjs/network/MTProtoSender.ts
  4. 2 2
      package-lock.json
  5. 1 1
      package.json

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "1.9.5";
+export const version = "1.9.6";

+ 15 - 10
gramjs/client/downloads.ts

@@ -31,7 +31,7 @@ export interface DownloadFileParams {
     dcId: number;
     /** How much to download. The library will download until it reaches this amount.<br/>
      *  can be useful for downloading by chunks */
-    fileSize: number;
+    fileSize?: number;
     /** Used to determine how many download tasks should be run in parallel. anything above 16 is unstable. */
     workers?: number;
     /** How much to download in each chunk. The larger the less requests to be made. (max is 512kb). */
@@ -76,8 +76,9 @@ export async function downloadFile(
     let { partSizeKb, end } = fileParams;
     const { fileSize, workers = 1 } = fileParams;
     const { dcId, progressCallback, start = 0 } = fileParams;
-
-    end = end && end < fileSize ? end : fileSize - 1;
+    if (end && fileSize) {
+        end = end < fileSize ? end : fileSize - 1;
+    }
 
     if (!partSizeKb) {
         partSizeKb = fileSize
@@ -441,15 +442,20 @@ export async function downloadProfilePhoto(
     entity: EntityLike,
     fileParams: DownloadProfilePhotoParams
 ) {
-    entity = await client.getEntity(entity);
-
     let photo;
-    if ("photo" in entity) {
+    if (typeof entity == "object" && "photo" in entity) {
         photo = entity.photo;
     } else {
-        throw new Error(
-            `Could not get photo from ${entity ? entity.className : undefined}`
-        );
+        entity = await client.getEntity(entity);
+        if ("photo" in entity) {
+            photo = entity.photo;
+        } else {
+            throw new Error(
+                `Could not get photo from ${
+                    entity ? entity.className : undefined
+                }`
+            );
+        }
     }
     let dcId;
     let loc;
@@ -468,7 +474,6 @@ export async function downloadProfilePhoto(
     }
     return client.downloadFile(loc, {
         dcId,
-        fileSize: 2 * 1024 * 1024,
         workers: 1,
     });
 }

+ 0 - 1
gramjs/network/MTProtoSender.ts

@@ -464,7 +464,6 @@ export class MTProtoSender {
                 body = await this._connection!.recv();
             } catch (e: any) {
                 /** when the server disconnects us we want to reconnect */
-                this._log.warn("Connection closed while receiving data");
                 if (!this.userDisconnected) {
                     this._log.error(e);
                     this._log.warn("Connection closed while receiving data");

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "telegram",
-  "version": "1.9.5",
+  "version": "1.9.6",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "telegram",
-      "version": "1.9.5",
+      "version": "1.9.6",
       "license": "MIT",
       "dependencies": {
         "@cryptography/aes": "^0.1.1",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "1.9.5",
+  "version": "1.9.6",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",