refactor: remove enqueueUpload from ITelegramService and BotPool

Per-bot queue replaces global upload queue — BotPool handles
queueing internally.

- Remove enqueueUpload method signature from ITelegramService interface
- Remove enqueueUpload method from BotPool class
- Remove import of enqueueUpload from upload-queue module
- Refactor forwardToStorage to call executeWithBotRetry directly
  instead of wrapping via enqueueUpload
- Fix trailing blank lines flagged by Biome formatter

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude
2026-07-29 13:14:26 +07:00
parent ea31c4c591
commit d7d6ae0f0d
2 changed files with 7 additions and 35 deletions
-11
View File
@@ -50,15 +50,4 @@ export interface ITelegramService {
* @returns Metadata including size, MIME type, download path, and bot token.
*/
getFileInfo(telegramFileId: string): Promise<TelegramFileInfo>;
/**
* Enqueue a task for sequential upload execution.
*
* Ensures only one Telegram upload runs at a time to avoid
* rate limits and resource contention.
*
* @param task - An async function performing the upload.
* @returns The result of the task.
*/
enqueueUpload<T>(task: () => Promise<T>): Promise<T>;
}
+7 -24
View File
@@ -13,7 +13,6 @@ import {
sendMethodMap,
type TelegramMessageResult,
} from './types';
import { enqueueUpload } from './upload-queue';
/**
* Sleep for a given number of milliseconds.
@@ -179,8 +178,7 @@ export class BotPool implements ITelegramService {
/**
* Forward a file chunk to the configured Telegram storage chat.
*
* The upload is queued (via {@link enqueueUpload}) and executed with
* automatic bot rotation on rate-limit errors.
* The upload is executed with automatic bot rotation on rate-limit errors.
*
* @param fileChunk - The file data (ReadStream, Buffer, or file path).
* @param fileName - The original file name.
@@ -198,15 +196,13 @@ export class BotPool implements ITelegramService {
while (attempt <= MAX_TRANSIENT_RETRIES) {
attempt++;
try {
const result = await this.enqueueUpload<TelegramMessageResult>(async () => {
const filePayload = { source: fileChunk, filename: fileName };
const sendMethodName = sendMethodMap[fileType] || 'sendDocument';
const payload = buildSendPayload(fileType, fileName);
const filePayload = { source: fileChunk, filename: fileName };
const sendMethodName = sendMethodMap[fileType] || 'sendDocument';
const payload = buildSendPayload(fileType, fileName);
return this.executeWithBotRetry<TelegramMessageResult>((activeBot) => {
const telegram = activeBot.telegram as unknown as Record<string, SendMethod>;
return telegram[sendMethodName](config.storageChatId, filePayload, payload);
});
const result = await this.executeWithBotRetry<TelegramMessageResult>((activeBot) => {
const telegram = activeBot.telegram as unknown as Record<string, SendMethod>;
return telegram[sendMethodName](config.storageChatId, filePayload, payload);
});
const uploadedFile = extractUploadedFile(result, fileType);
@@ -302,19 +298,6 @@ export class BotPool implements ITelegramService {
});
throw lastError;
}
/**
* Enqueue a task for sequential upload execution.
*
* Delegates to the shared upload queue to ensure only a limited number
* of Telegram uploads run concurrently.
*
* @param task - An async function performing the upload.
* @returns The result of the task.
*/
enqueueUpload<T>(task: () => Promise<T>): Promise<T> {
return enqueueUpload(task);
}
}
/**