master
icechen 2022-02-25 02:38:45 +08:00
parent 8b8cfc64bc
commit 907409203c
4 changed files with 21 additions and 5 deletions

View File

@ -8,7 +8,7 @@ function Home() {
useEffect(function () { useEffect(function () {
getMe() getMe()
.then(function (user) { .then(function (user) {
console.log(user); setIsSignIn(true);
}) })
.catch(function (error) { .catch(function (error) {
if (error.code === 401) { if (error.code === 401) {

View File

@ -1,5 +1,6 @@
import Client from "mtproton/envs/browser"; import Client from "mtproton/envs/browser";
import { rand_id } from "../utils/rand"; import { rand_id } from "../utils/rand";
import { obj } from "../utils/log";
class TelegramHelper { class TelegramHelper {
private client: any; private client: any;
@ -7,14 +8,17 @@ class TelegramHelper {
this.client = new Client({ this.client = new Client({
api_id: appID, api_id: appID,
api_hash: appHash, api_hash: appHash,
test: true, test: false,
}); });
this.client.setDefaultDc(1); this.client.setDefaultDc(1);
} }
async call(method: string, params?: object, options?: object): Promise<any> { async call(method: string, params?: object, options?: object): Promise<any> {
try { try {
return await this.client.call(method, params, options); console.dir(`${method} req\n${obj(params)}`);
let resp = await this.client.call(method, params, options);
console.dir(`${method} resp\n${obj(resp)}`);
return resp;
} catch (error) { } catch (error) {
console.log(`${method} error:`, error); console.log(`${method} error:`, error);

View File

@ -1,8 +1,8 @@
import Telegram from "./telegram"; import Telegram from "./telegram";
async function getMe() { async function getMe() {
return await Telegram.call("users.getUsers", { return await Telegram.call("users.getFullUser", {
id: [{ _: "inputUserSelf" }], id: { _: "inputUserSelf" },
}); });
} }

12
src/utils/log.ts 100644
View File

@ -0,0 +1,12 @@
const maxToLog = 10240;
export function obj(obj: any): string {
if (!obj) {
return "null";
}
let s = JSON.stringify(obj, null, 2);
if (s.length > maxToLog) {
s = s.substr(0, maxToLog) + "...";
}
return s;
}