feat: apply per-account Premium 4GB upload limit to bypass repacking

This commit is contained in:
2026-05-02 23:28:00 +02:00
parent 579276ee2d
commit 4f59d19ac2
2 changed files with 13 additions and 9 deletions

View File

@@ -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<string[]> {
export async function byteLevelSplit(filePath: string, maxPartSize?: bigint): Promise<string[]> {
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[] = [];

View File

@@ -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;
}