feat(torrents): support piece priority

This commit is contained in:
NimBold
2026-08-02 09:22:15 +03:30
parent a46a64994d
commit 67023d3f0d
19 changed files with 379 additions and 18 deletions
+15
View File
@@ -8,6 +8,7 @@ import {
canonicalizeDownloadFileName,
isValidTorrentExcludeTrackerList,
isValidTorrentTrackerList,
normalizeTorrentPrioritizePiece,
redactDownloadForPersistence,
resolveDownloadConnections
} from './downloads';
@@ -77,6 +78,20 @@ describe('Torrent tracker input validation', () => {
});
});
describe('Torrent piece priority validation', () => {
it('normalizes head and tail preview policies', () => {
expect(normalizeTorrentPrioritizePiece(' tail = 64k, HEAD ')).toBe('head,tail=64K');
expect(normalizeTorrentPrioritizePiece('head=1m,tail=1024M')).toBe('head=1M,tail=1024M');
expect(normalizeTorrentPrioritizePiece('')).toBeNull();
});
it('rejects duplicate, unsupported, malformed, and oversized policies', () => {
for (const value of ['head,head', 'middle', 'head=0K', 'tail=1G', 'head=1K,', 'head=1025M']) {
expect(normalizeTorrentPrioritizePiece(value)).toBeNull();
}
});
});
describe('download connection resolution', () => {
it('uses a clamped fallback for legacy rows without a saved value', () => {
expect(resolveDownloadConnections(undefined, 8)).toBe(8);