mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
feat: apply per-account Premium 4GB upload limit to bypass repacking
This commit is contained in:
@@ -18,20 +18,22 @@ const log = childLogger("split");
|
|||||||
const MAX_PART_SIZE = BigInt(config.maxPartSizeMB) * 1024n * 1024n;
|
const MAX_PART_SIZE = BigInt(config.maxPartSizeMB) * 1024n * 1024n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a file into ≤2GB parts using byte-level splitting.
|
* Split a file into parts using byte-level splitting.
|
||||||
* Returns paths to the split parts. If the file is already ≤2GB, returns the original path.
|
* 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 stats = await stat(filePath);
|
||||||
const fileSize = BigInt(stats.size);
|
const fileSize = BigInt(stats.size);
|
||||||
|
|
||||||
if (fileSize <= MAX_PART_SIZE) {
|
if (fileSize <= effectiveMax) {
|
||||||
return [filePath];
|
return [filePath];
|
||||||
}
|
}
|
||||||
|
|
||||||
const dir = path.dirname(filePath);
|
const dir = path.dirname(filePath);
|
||||||
const baseName = path.basename(filePath);
|
const baseName = path.basename(filePath);
|
||||||
const partSize = Number(MAX_PART_SIZE);
|
const partSize = Number(effectiveMax);
|
||||||
const totalParts = Math.ceil(Number(fileSize) / partSize);
|
const totalParts = Math.ceil(Number(fileSize) / partSize);
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -342,7 +342,9 @@ export async function runWorkerForAccount(
|
|||||||
id: account.id,
|
id: account.id,
|
||||||
phone: account.phone,
|
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).
|
// Load all chats into TDLib's local cache using loadChats (the recommended API).
|
||||||
// Without this, getChat/searchChatMessages fail with "Chat not found".
|
// Without this, getChat/searchChatMessages fail with "Chat not found".
|
||||||
@@ -455,7 +457,7 @@ export async function runWorkerForAccount(
|
|||||||
topicCreator: null,
|
topicCreator: null,
|
||||||
sourceTopicId: null,
|
sourceTopicId: null,
|
||||||
accountLog,
|
accountLog,
|
||||||
maxUploadSize: BigInt(config.maxPartSizeMB) * 1024n * 1024n,
|
maxUploadSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (forum) {
|
if (forum) {
|
||||||
@@ -1116,7 +1118,7 @@ async function processOneArchiveSet(
|
|||||||
});
|
});
|
||||||
const concatPath = path.join(setDir, `${archiveSet.baseName}.concat`);
|
const concatPath = path.join(setDir, `${archiveSet.baseName}.concat`);
|
||||||
await concatenateFiles(tempPaths, concatPath);
|
await concatenateFiles(tempPaths, concatPath);
|
||||||
splitPaths = await byteLevelSplit(concatPath);
|
splitPaths = await byteLevelSplit(concatPath, ctx.maxUploadSize);
|
||||||
uploadPaths = splitPaths;
|
uploadPaths = splitPaths;
|
||||||
// Clean up the concat intermediate file
|
// Clean up the concat intermediate file
|
||||||
await unlink(concatPath).catch(() => {});
|
await unlink(concatPath).catch(() => {});
|
||||||
@@ -1130,7 +1132,7 @@ async function processOneArchiveSet(
|
|||||||
currentFileNum: setIdx + 1,
|
currentFileNum: setIdx + 1,
|
||||||
totalFiles: totalSets,
|
totalFiles: totalSets,
|
||||||
});
|
});
|
||||||
splitPaths = await byteLevelSplit(tempPaths[0]);
|
splitPaths = await byteLevelSplit(tempPaths[0], ctx.maxUploadSize);
|
||||||
uploadPaths = splitPaths;
|
uploadPaths = splitPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user