Преглед на файлове

Make working with browsers easier.

painor преди 3 години
родител
ревизия
124a9d642a
променени са 6 файла, в които са добавени 16 реда и са изтрити 9 реда
  1. 1 1
      gramjs/Version.ts
  2. 4 1
      gramjs/client/telegramBaseClient.ts
  3. 6 2
      gramjs/sessions/StoreSession.ts
  4. 2 2
      gramjs/tl/api.js
  5. 2 2
      package-lock.json
  6. 1 1
      package.json

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "1.8.1";
+export const version = "1.8.2";

+ 4 - 1
gramjs/client/telegramBaseClient.ts

@@ -4,7 +4,7 @@ import {
     ConnectionTCPFull,
     ConnectionTCPObfuscated,
 } from "../network/connection";
-import { Session } from "../sessions";
+import { Session, StoreSession } from "../sessions";
 import { Logger } from "../extensions";
 import { Api } from "../tl";
 
@@ -192,6 +192,9 @@ export class TelegramBaseClient {
             this._log = clientParams.baseLogger;
         }
         this._log.debug("Running gramJS version " + version);
+        if (session && typeof session=="string"){
+            session = new StoreSession(session);
+        }
         if (!(session instanceof Session)) {
             throw new Error(
                 "Only StringSession and StoreSessions are supported currently :( "

+ 6 - 2
gramjs/sessions/StoreSession.ts

@@ -1,7 +1,6 @@
 import { MemorySession } from "./Memory";
 import store from "store2";
 import { AuthKey } from "../crypto/AuthKey";
-import { LocalStorage } from "node-localstorage";
 
 export class StoreSession extends MemorySession {
     private readonly sessionName: string;
@@ -9,7 +8,12 @@ export class StoreSession extends MemorySession {
 
     constructor(sessionName: string) {
         super();
-        this.store = store.area("fs", new LocalStorage("./" + sessionName));
+        if (typeof localStorage === "undefined" || localStorage === null) {
+            const LocalStorage = require('node-localstorage').LocalStorage;
+            this.store = store.area("fs", new LocalStorage("./" + sessionName));
+        }else{
+            this.store = store.area("fs", localStorage);
+        }
         this.sessionName = sessionName + ":";
     }
 

+ 2 - 2
gramjs/tl/api.js

@@ -23,8 +23,8 @@ if (IS_NODE) {
     tlContent = fs.readFileSync(__dirname + "/static/api.tl", "utf-8");
     schemeContent = fs.readFileSync(__dirname + "/static/schema.tl", "utf-8");
 } else {
-    tlContent = require("./static/api.tl").default;
-    schemeContent = require("./static/schema.tl").default;
+    tlContent = require("!!raw-loader!./static/api.tl").default;
+    schemeContent = require("!!raw-loader!./static/schema.tl").default;
 }
 const NAMED_AUTO_CASTS = new Set(["chatId,int"]);
 const NAMED_BLACKLIST = new Set(["discardEncryption"]);

+ 2 - 2
package-lock.json

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

+ 1 - 1
package.json

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