mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-30 16:55:08 +08:00
chore: replace telegram with teleproto (#22915)
https://github.com/gram-js/gramjs/pull/837
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import type { Context } from 'hono';
|
||||
import { stream } from 'hono/streaming';
|
||||
import type { TelegramClient } from 'telegram';
|
||||
import { Api } from 'telegram';
|
||||
import type { IterDownloadFunction } from 'telegram/client/downloads.js';
|
||||
import { returnBigInt as bigInt } from 'telegram/Helpers.js';
|
||||
import { getAppropriatedPartSize } from 'telegram/Utils.js';
|
||||
import type { TelegramClient } from 'teleproto';
|
||||
import { Api } from 'teleproto';
|
||||
import { returnBigInt as bigInt } from 'teleproto/Helpers.js';
|
||||
|
||||
import { config } from '@/config';
|
||||
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
||||
@@ -86,30 +84,32 @@ export async function* streamThumbnail(client: TelegramClient, doc: Api.Document
|
||||
}
|
||||
|
||||
export async function* streamDocument(client: TelegramClient, obj: Api.Document, thumbSize = '', offset?: bigInt.BigInteger, limit?: bigInt.BigInteger) {
|
||||
const chunkSize = (obj.size ? getAppropriatedPartSize(obj.size) : 64) * 1024;
|
||||
const iterFileParams: IterDownloadFunction = {
|
||||
file: new Api.InputDocumentFileLocation({
|
||||
const requestSize = 512 * 1024; // MAX_CHUNK_SIZE
|
||||
let skip = offset ? offset.mod(requestSize).toJSNumber() : 0;
|
||||
const alignedOffset = offset?.subtract(skip);
|
||||
// console.log('starting iterDownload');
|
||||
const chunks = client.iterDownload(
|
||||
new Api.InputDocumentFileLocation({
|
||||
id: obj.id,
|
||||
accessHash: obj.accessHash,
|
||||
fileReference: obj.fileReference,
|
||||
thumbSize,
|
||||
}),
|
||||
chunkSize,
|
||||
requestSize: 512 * 1024, // MAX_CHUNK_SIZE
|
||||
dcId: obj.dcId,
|
||||
offset: undefined,
|
||||
limit: undefined,
|
||||
};
|
||||
if (offset) {
|
||||
iterFileParams.offset = offset;
|
||||
{
|
||||
requestSize,
|
||||
dcId: obj.dcId,
|
||||
offset: alignedOffset,
|
||||
limit: limit && alignedOffset ? limit.subtract(alignedOffset).add(1).valueOf() : undefined,
|
||||
}
|
||||
);
|
||||
for await (const chunk of chunks) {
|
||||
if (skip >= chunk.length) {
|
||||
skip -= chunk.length;
|
||||
continue;
|
||||
}
|
||||
yield skip ? chunk.subarray(skip) : chunk;
|
||||
skip = 0;
|
||||
}
|
||||
if (limit) {
|
||||
iterFileParams.limit = limit.valueOf();
|
||||
}
|
||||
// console.log('starting iterDownload');
|
||||
const stream = client.iterDownload(iterFileParams);
|
||||
yield* stream;
|
||||
await stream.close();
|
||||
}
|
||||
|
||||
function parseRange(range: string, length: bigInt.BigInteger) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import readline from 'node:readline';
|
||||
|
||||
import { TelegramClient } from 'telegram';
|
||||
import { StringSession } from 'telegram/sessions/index.js';
|
||||
import { TelegramClient } from 'teleproto';
|
||||
import { StringSession } from 'teleproto/sessions/index.js';
|
||||
import winston from 'winston';
|
||||
|
||||
function userInput(question) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import type { Context } from 'hono';
|
||||
import { Api } from 'telegram';
|
||||
import { Api } from 'teleproto';
|
||||
|
||||
import NotFoundError from '@/errors/types/not-found';
|
||||
import { configureMiddlewares, handleMedia } from '@/routes/telegram/channel-media';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import type { Context } from 'hono';
|
||||
import { Api } from 'telegram';
|
||||
import { HTMLParser } from 'telegram/extensions/html.js';
|
||||
import { returnBigInt } from 'telegram/Helpers.js';
|
||||
import { getDisplayName } from 'telegram/Utils.js';
|
||||
import { Api } from 'teleproto';
|
||||
import { HTMLParser } from 'teleproto/extensions/html.js';
|
||||
import { returnBigInt } from 'teleproto/Helpers.js';
|
||||
import { getDisplayName } from 'teleproto/Utils.js';
|
||||
|
||||
import type { DataItem } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
@@ -22,10 +22,11 @@ export async function getPollResults(client, message, m: Api.MessageMediaPoll) {
|
||||
}
|
||||
const txt = `<h4>${m.poll.quiz ? 'Quiz' : 'Poll'}: ${m.poll.question.text}</h4>
|
||||
<div><ul>${m.poll.answers
|
||||
.filter((a) => a instanceof Api.PollAnswer)
|
||||
.map((a) => {
|
||||
let answerTxt = a.text.text;
|
||||
const result = results.results?.find((r) => r.option.buffer === a.option.buffer);
|
||||
if (result && results.totalVoters) {
|
||||
if (result?.voters !== undefined && results.totalVoters) {
|
||||
answerTxt = `<strong>${Math.round((result.voters / results.totalVoters) * 100)}%</strong>: ${answerTxt}`;
|
||||
}
|
||||
return `<li>${answerTxt}</li>`;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Api, TelegramClient } from 'telegram';
|
||||
import type { UserAuthParams } from 'telegram/client/auth';
|
||||
import { StringSession } from 'telegram/sessions/index.js';
|
||||
import { Api, TelegramClient } from 'teleproto';
|
||||
import type { UserAuthParams } from 'teleproto/client/auth';
|
||||
import { StringSession } from 'teleproto/sessions/index.js';
|
||||
|
||||
import { config } from '@/config';
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@
|
||||
"simplecc-wasm": "1.1.1",
|
||||
"socks-proxy-agent": "10.1.0",
|
||||
"source-map": "0.8.0",
|
||||
"telegram": "2.26.22",
|
||||
"teleproto": "1.228.5",
|
||||
"title": "4.0.1",
|
||||
"tldts": "7.4.10",
|
||||
"tosource": "2.0.0-alpha.3",
|
||||
|
||||
Generated
+20
-434
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user