update
parent
26cb0eaef1
commit
3044a43a89
|
@ -14,11 +14,10 @@ import Telegram, {
|
||||||
uploadBigFile,
|
uploadBigFile,
|
||||||
sendFile,
|
sendFile,
|
||||||
downloadFile,
|
downloadFile,
|
||||||
} from "./telegram";
|
} from "./telegram/telegram";
|
||||||
import SendIcon from "@mui/icons-material/Send";
|
import SendIcon from "@mui/icons-material/Send";
|
||||||
import { User } from "./user";
|
import { User } from "./user";
|
||||||
import { Download, Upload } from "@mui/icons-material";
|
import { Download, Upload } from "@mui/icons-material";
|
||||||
import ab2str from "./utils/arraybuffer2str";
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
let [phone, setPhone] = useState("");
|
let [phone, setPhone] = useState("");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Autocomplete, Box, TextField } from "@mui/material";
|
import { Autocomplete, Box, TextField } from "@mui/material";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import Telegram from "../telegram";
|
import Telegram from "../telegram/telegram";
|
||||||
|
|
||||||
export interface Country {
|
export interface Country {
|
||||||
default_name: string;
|
default_name: string;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Client from "mtproton/envs/browser";
|
import Client from "mtproton/envs/browser";
|
||||||
import between from "./utils/rand";
|
import { rand_id } from "../utils/rand";
|
||||||
|
|
||||||
class TelegramHelper {
|
class TelegramHelper {
|
||||||
private client: any;
|
private client: any;
|
||||||
|
@ -51,7 +51,7 @@ class TelegramHelper {
|
||||||
async function uploadBigFile(
|
async function uploadBigFile(
|
||||||
bytes: ArrayBuffer
|
bytes: ArrayBuffer
|
||||||
): Promise<{ file_id: number; total_part: number }> {
|
): Promise<{ file_id: number; total_part: number }> {
|
||||||
let file_id = between(10000, 99999);
|
let file_id = rand_id();
|
||||||
console.log("file_id", file_id);
|
console.log("file_id", file_id);
|
||||||
|
|
||||||
let uploadBytes = new Uint8Array(bytes);
|
let uploadBytes = new Uint8Array(bytes);
|
||||||
|
@ -96,7 +96,7 @@ function inputFile(file_id: number, part_number: number, file_name: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendFile(inputFile: any, type: string) {
|
function sendFile(inputFile: any, type: string) {
|
||||||
let random_id = between(10000, 99999);
|
let random_id = rand_id();
|
||||||
console.log("random_id", random_id);
|
console.log("random_id", random_id);
|
||||||
return Telegram.call("messages.sendMedia", {
|
return Telegram.call("messages.sendMedia", {
|
||||||
peer: {
|
peer: {
|
||||||
|
@ -113,7 +113,7 @@ function sendFile(inputFile: any, type: string) {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
random_id: between(10000, 99999),
|
random_id: rand_id(),
|
||||||
message: "test",
|
message: "test",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -167,54 +167,5 @@ const appID = 18987971;
|
||||||
const appHash = "fcfd9e6ed3f9e48a360bb57cc0d59d98";
|
const appHash = "fcfd9e6ed3f9e48a360bb57cc0d59d98";
|
||||||
let Telegram = new TelegramHelper(appID, appHash);
|
let Telegram = new TelegramHelper(appID, appHash);
|
||||||
|
|
||||||
function hexStringToArrayBuffer(hexString: string) {
|
|
||||||
// remove the leading 0x
|
|
||||||
hexString = hexString.replace(/^0x/, "");
|
|
||||||
|
|
||||||
// ensure even number of characters
|
|
||||||
if (hexString.length % 2 != 0) {
|
|
||||||
console.log(
|
|
||||||
"WARNING: expecting an even number of characters in the hexString"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for some non-hex characters
|
|
||||||
let bad = hexString.match(/[G-Z\s]/i);
|
|
||||||
if (bad) {
|
|
||||||
console.log("WARNING: found non-hex characters", bad);
|
|
||||||
}
|
|
||||||
|
|
||||||
// split the string into pairs of octets
|
|
||||||
let pairs = hexString.match(/[\dA-F]{2}/gi);
|
|
||||||
|
|
||||||
// convert the octets to integers
|
|
||||||
// @ts-ignore
|
|
||||||
let integers = pairs.map(function (s: string) {
|
|
||||||
return parseInt(s, 16);
|
|
||||||
});
|
|
||||||
|
|
||||||
let array = new Uint8Array(integers);
|
|
||||||
console.log(array);
|
|
||||||
|
|
||||||
return array.buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
function arrayBufferToHex(arrayBuffer: ArrayBuffer) {
|
|
||||||
if (typeof arrayBuffer !== "object" || arrayBuffer === null) {
|
|
||||||
throw new TypeError("Expected input to be an ArrayBuffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
let view = new Uint8Array(arrayBuffer);
|
|
||||||
let result = "";
|
|
||||||
let value;
|
|
||||||
|
|
||||||
for (let i = 0; i < view.length; i++) {
|
|
||||||
value = view[i].toString(16);
|
|
||||||
result += value.length === 1 ? "0" + value : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Telegram;
|
export default Telegram;
|
||||||
export { uploadBigFile, inputFile, sendFile, downloadFile };
|
export { uploadBigFile, inputFile, sendFile, downloadFile };
|
|
@ -2,4 +2,8 @@ function between(min: number, max: number): number {
|
||||||
return Math.floor(Math.random() * (max - min) + min);
|
return Math.floor(Math.random() * (max - min) + min);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default between;
|
function rand_id(): number {
|
||||||
|
return between(100000, 999999);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { between, rand_id };
|
||||||
|
|
Loading…
Reference in New Issue