mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
- Add invokeWithTimeout wrapper for TDLib API calls (2min timeout per call) - Add stuck detection to getChannelMessages: break if from_message_id doesn't advance - Add stuck detection to getTopicMessages: same protection for topic scanning - Add stuck detection to getForumTopicList: break if pagination offsets don't advance - Add max page limit (5000) to all scanning loops to prevent infinite pagination - Add mutex wait timeout (30min) to prevent indefinite blocking when holder hangs - Add cycle timeout (4h default, configurable via WORKER_CYCLE_TIMEOUT_MINUTES) - Fix end-of-page detection to use actual limit value instead of hardcoded 100 Co-authored-by: xCyanGrizzly <53275238+xCyanGrizzly@users.noreply.github.com>
77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
const patterns = [
|
|
// pack.zip.001, pack.zip.002
|
|
{
|
|
regex: /^(.+\.zip)\.(\d{3,})$/i,
|
|
format: "ZIP",
|
|
pattern: "ZIP_NUMBERED",
|
|
getBaseName: (m) => m[1],
|
|
getPartNumber: (m) => parseInt(m[2], 10),
|
|
},
|
|
// pack.z01, pack.z02 (legacy split — final part is pack.zip)
|
|
{
|
|
regex: /^(.+)\.z(\d{2,})$/i,
|
|
format: "ZIP",
|
|
pattern: "ZIP_LEGACY",
|
|
getBaseName: (m) => m[1],
|
|
getPartNumber: (m) => parseInt(m[2], 10),
|
|
},
|
|
// pack.part1.rar, pack.part2.rar
|
|
{
|
|
regex: /^(.+)\.part(\d+)\.rar$/i,
|
|
format: "RAR",
|
|
pattern: "RAR_PART",
|
|
getBaseName: (m) => m[1],
|
|
getPartNumber: (m) => parseInt(m[2], 10),
|
|
},
|
|
// pack.r00, pack.r01 (legacy split — final part is pack.rar)
|
|
{
|
|
regex: /^(.+)\.r(\d{2,})$/i,
|
|
format: "RAR",
|
|
pattern: "RAR_LEGACY",
|
|
getBaseName: (m) => m[1],
|
|
getPartNumber: (m) => parseInt(m[2], 10),
|
|
},
|
|
];
|
|
/**
|
|
* Detect if a filename is an archive and extract multipart info.
|
|
*/
|
|
export function detectArchive(fileName) {
|
|
// Check multipart patterns first
|
|
for (const p of patterns) {
|
|
const match = fileName.match(p.regex);
|
|
if (match) {
|
|
return {
|
|
baseName: p.getBaseName(match),
|
|
partNumber: p.getPartNumber(match),
|
|
format: p.format,
|
|
pattern: p.pattern,
|
|
};
|
|
}
|
|
}
|
|
// Single .zip file — could be a standalone or the final part of a ZIP_LEGACY set
|
|
if (/\.zip$/i.test(fileName)) {
|
|
return {
|
|
baseName: fileName.replace(/\.zip$/i, ""),
|
|
partNumber: -1, // -1 signals "could be single or final legacy part"
|
|
format: "ZIP",
|
|
pattern: "SINGLE",
|
|
};
|
|
}
|
|
// Single .rar file — could be standalone or final part of RAR_LEGACY set
|
|
if (/\.rar$/i.test(fileName)) {
|
|
return {
|
|
baseName: fileName.replace(/\.rar$/i, ""),
|
|
partNumber: -1,
|
|
format: "RAR",
|
|
pattern: "SINGLE",
|
|
};
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* Check if a filename looks like any archive attachment we should process.
|
|
*/
|
|
export function isArchiveAttachment(fileName) {
|
|
return detectArchive(fileName) !== null;
|
|
}
|
|
//# sourceMappingURL=detect.js.map
|