Browse Source

Fix uploadFile and downloadFile

Painor 3 years ago
parent
commit
b99879464c

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.8.0";
+export const version = "2.8.3";

+ 2 - 9
gramjs/client/TelegramClient.ts

@@ -12,14 +12,7 @@ import * as userMethods from "./users";
 import * as chatMethods from "./chats";
 import * as dialogMethods from "./dialogs";
 import * as twoFA from "./2fa";
-import type {
-    ButtonLike,
-    Entity,
-    EntityLike,
-    MessageIDLike,
-    OutFile,
-    ProgressCallback,
-} from "../define";
+import type { ButtonLike, Entity, EntityLike, MessageIDLike } from "../define";
 import { Api } from "../tl";
 import { sanitizeParseMode } from "../Utils";
 import type { EventBuilder } from "../events/common";
@@ -1372,7 +1365,7 @@ export class TelegramClient extends TelegramBaseClient {
             dcId: this.session.dcId,
             loggers: this._log,
             proxy: this._proxy,
-            socket: this.socket,
+            socket: this.networkSocket,
             testServers: this.testServers,
         });
         const newConnection = await this._sender.connect(connection);

+ 3 - 10
gramjs/client/telegramBaseClient.ts

@@ -229,7 +229,7 @@ export abstract class TelegramBaseClient {
     /** @hidden */
     public testServers: boolean;
     /** @hidden */
-    public socket: PromisedNetSockets | PromisedWebSockets;
+    public networkSocket: typeof PromisedNetSockets | typeof PromisedWebSockets;
 
     constructor(
         session: string | Session,
@@ -271,14 +271,7 @@ export abstract class TelegramBaseClient {
             clientParams.maxConcurrentDownloads || 1
         );
         this.testServers = clientParams.testServers || false;
-        if (
-            clientParams.networkSocket!.constructor ===
-            PromisedNetSockets.constructor
-        ) {
-            this.socket = new clientParams.networkSocket!(this._proxy);
-        } else {
-            this.socket = new clientParams.networkSocket!();
-        }
+        this.networkSocket = clientParams.networkSocket || PromisedNetSockets;
         if (!(clientParams.connection instanceof Function)) {
             throw new Error("Connection should be a class not an instance");
         }
@@ -437,7 +430,7 @@ export abstract class TelegramBaseClient {
                         loggers: this._log,
                         proxy: this._proxy,
                         testServers: this.testServers,
-                        socket: this.socket,
+                        socket: this.networkSocket,
                     })
                 );
 

+ 10 - 3
gramjs/network/MTProtoSender.ts

@@ -13,7 +13,12 @@
  */
 import { AuthKey } from "../crypto/AuthKey";
 import { MTProtoState } from "./MTProtoState";
-import { BinaryReader, Logger } from "../extensions";
+import {
+    BinaryReader,
+    Logger,
+    PromisedNetSockets,
+    PromisedWebSockets,
+} from "../extensions";
 import { MessagePacker } from "../extensions";
 import { GZIPPacked, MessageContainer, RPCResult, TLMessage } from "../tl/core";
 import { Api } from "../tl";
@@ -936,7 +941,9 @@ export class MTProtoSender {
         // For some reason reusing existing connection caused stuck requests
         const constructor = this._connection!
             .constructor as unknown as typeof Connection;
-
+        const socket = this._connection!.socket.constructor as
+            | typeof PromisedNetSockets
+            | typeof PromisedWebSockets;
         const newConnection = new constructor({
             ip: this._connection!._ip,
             port: this._connection!._port,
@@ -944,7 +951,7 @@ export class MTProtoSender {
             loggers: this._connection!._log,
             proxy: this._connection!._proxy,
             testServers: this._connection!._testServers,
-            socket: this._connection!.socket,
+            socket: socket,
         });
         await this.connect(newConnection, true);
 

+ 2 - 2
gramjs/network/connection/Connection.ts

@@ -14,7 +14,7 @@ interface ConnectionInterfaceParams {
     dcId: number;
     loggers: Logger;
     proxy?: ProxyInterface;
-    socket: PromisedNetSockets | PromisedWebSockets;
+    socket: typeof PromisedNetSockets | typeof PromisedWebSockets;
     testServers: boolean;
 }
 
@@ -67,7 +67,7 @@ class Connection {
         this._obfuscation = undefined; // TcpObfuscated and MTProxy
         this._sendArray = new AsyncQueue();
         this._recvArray = new AsyncQueue();
-        this.socket = socket;
+        this.socket = new socket(proxy);
         this._testServers = testServers;
     }
 

+ 1 - 1
gramjs/network/connection/TCPMTProxy.ts

@@ -127,7 +127,7 @@ interface TCPMTProxyInterfaceParams {
     dcId: number;
     loggers: Logger;
     proxy: ProxyInterface;
-    socket: PromisedNetSockets | PromisedWebSockets;
+    socket: typeof PromisedNetSockets | typeof PromisedWebSockets;
     testServers: boolean;
 }