From 4f59d19ac20ae925f61180bc052bbbcd99f35db4 Mon Sep 17 00:00:00 2001 From: xCyanGrizzly Date: Sat, 2 May 2026 23:28:00 +0200 Subject: [PATCH] feat: apply per-account Premium 4GB upload limit to bypass repacking --- worker/src/archive/split.ts | 12 +++++++----- worker/src/worker.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/worker/src/archive/split.ts b/worker/src/archive/split.ts index c065bfe..1bd2953 100644 --- a/worker/src/archive/split.ts +++ b/worker/src/archive/split.ts @@ -18,20 +18,22 @@ const log = childLogger("split"); const MAX_PART_SIZE = BigInt(config.maxPartSizeMB) * 1024n * 1024n; /** - * Split a file into ≤2GB parts using byte-level splitting. - * Returns paths to the split parts. If the file is already ≤2GB, returns the original path. + * Split a file into parts using byte-level splitting. + * Returns paths to the split parts. If the file fits in one part, returns the original path. + * Pass maxPartSize to override the global default (e.g., 3950 MiB for Premium accounts). */ -export async function byteLevelSplit(filePath: string): Promise { +export async function byteLevelSplit(filePath: string, maxPartSize?: bigint): Promise { + const effectiveMax = maxPartSize ?? MAX_PART_SIZE; const stats = await stat(filePath); const fileSize = BigInt(stats.size); - if (fileSize <= MAX_PART_SIZE) { + if (fileSize <= effectiveMax) { return [filePath]; } const dir = path.dirname(filePath); const baseName = path.basename(filePath); - const partSize = Number(MAX_PART_SIZE); + const partSize = Number(effectiveMax); const totalParts = Math.ceil(Number(fileSize) / partSize); const parts: string[] = []; diff --git a/worker/src/worker.ts b/worker/src/worker.ts index 384d2f6..3e87341 100644 --- a/worker/src/worker.ts +++ b/worker/src/worker.ts @@ -342,7 +342,9 @@ export async function runWorkerForAccount( id: account.id, phone: account.phone, }); - void isPremium; // will be used in Task 6 for upload limits + const maxUploadSize = isPremium + ? 3950n * 1024n * 1024n + : BigInt(config.maxPartSizeMB) * 1024n * 1024n; // Load all chats into TDLib's local cache using loadChats (the recommended API). // Without this, getChat/searchChatMessages fail with "Chat not found". @@ -455,7 +457,7 @@ export async function runWorkerForAccount( topicCreator: null, sourceTopicId: null, accountLog, - maxUploadSize: BigInt(config.maxPartSizeMB) * 1024n * 1024n, + maxUploadSize, }; if (forum) { @@ -1116,7 +1118,7 @@ async function processOneArchiveSet( }); const concatPath = path.join(setDir, `${archiveSet.baseName}.concat`); await concatenateFiles(tempPaths, concatPath); - splitPaths = await byteLevelSplit(concatPath); + splitPaths = await byteLevelSplit(concatPath, ctx.maxUploadSize); uploadPaths = splitPaths; // Clean up the concat intermediate file await unlink(concatPath).catch(() => {}); @@ -1130,7 +1132,7 @@ async function processOneArchiveSet( currentFileNum: setIdx + 1, totalFiles: totalSets, }); - splitPaths = await byteLevelSplit(tempPaths[0]); + splitPaths = await byteLevelSplit(tempPaths[0], ctx.maxUploadSize); uploadPaths = splitPaths; }