Просмотр исходного кода

GramJS: Various fixes for download and floodwaits (#623)

painor 5 лет назад
Родитель
Сommit
7883cef4af
2 измененных файлов с 16 добавлено и 19 удалено
  1. 10 0
      src/api/gramjs/methods/media.ts
  2. 6 19
      src/lib/gramjs/client/TelegramClient.js

+ 10 - 0
src/api/gramjs/methods/media.ts

@@ -11,7 +11,13 @@ import { getEntityTypeById } from '../gramjsBuilders';
 import { blobToDataUri } from '../../../util/files';
 import * as cacheApi from '../../../util/cacheApi';
 
+<<<<<<< HEAD
 type EntityType = 'msg' | 'sticker' | 'gif' | 'channel' | 'chat' | 'user' | 'stickerSet';
+=======
+type EntityType = 'msg' | 'sticker' | 'wallpaper' | 'gif' | 'channel' | 'chat' | 'user' | 'stickerSet';
+
+const MAX_WORKERS = 16;
+>>>>>>> 90fbcf87... GramJS: Various fixes for download and floodwaits (#623)
 
 export default async function downloadMedia(
   {
@@ -112,7 +118,11 @@ async function download(
 
   if (entityType === 'msg' || entityType === 'sticker' || entityType === 'gif') {
     const data = await client.downloadMedia(entity, {
+<<<<<<< HEAD
       sizeType, start, end, progressCallback: onProgress, workers: 16,
+=======
+      sizeType, start, end, progressCallback: onProgress, workers: MAX_WORKERS,
+>>>>>>> 90fbcf87... GramJS: Various fixes for download and floodwaits (#623)
     });
     let mimeType;
     let fullSize;

+ 6 - 19
src/lib/gramjs/client/TelegramClient.js

@@ -429,9 +429,12 @@ class TelegramClient {
             args.progressCallback(0)
         }
 
-        if (!workers) {
+        if (!workers || !fileSize) {
             workers = 1
         }
+        if (!args.end){
+            args.end = fileSize
+        }
 
         try {
             let limit = partSize
@@ -495,7 +498,7 @@ class TelegramClient {
                 }
             }
         } finally {
-            // TODO
+
         }
     }
 
@@ -817,22 +820,7 @@ class TelegramClient {
         }
         //await request.resolve(this, utils)
 
-        if (request.CONSTRUCTOR_ID in this._floodWaitedRequests) {
-            const due = this._floodWaitedRequests[request.CONSTRUCTOR_ID]
-            const diff = Math.round(due - new Date().getTime() / 1000)
-            if (diff <= 3) {
-                delete this._floodWaitedRequests[request.CONSTRUCTOR_ID]
-            } else if (diff <= this.floodSleepLimit) {
-                this._log.info(`Sleeping early for ${diff}s on flood wait`)
-                await sleep(diff)
-                delete this._floodWaitedRequests[request.CONSTRUCTOR_ID]
-            } else {
-                throw new FloodWaitError({
-                    request: request,
-                    capture: diff,
-                })
-            }
-        }
+
         this._lastRequest = new Date().getTime()
         let attempt = 0
         for (attempt = 0; attempt < this._requestRetries; attempt++) {
@@ -848,7 +836,6 @@ class TelegramClient {
                     this._log.warn(`Telegram is having internal issues ${e.constructor.name}`)
                     await sleep(2000)
                 } else if (e instanceof errors.FloodWaitError || e instanceof errors.FloodTestPhoneWaitError) {
-                    this._floodWaitedRequests[request.CONSTRUCTOR_ID] = new Date().getTime() / 1000 + e.seconds
                     if (e.seconds <= this.floodSleepLimit) {
                         this._log.info(`Sleeping for ${e.seconds}s on flood wait`)
                         await sleep(e.seconds * 1000)