fix(tracker-adapters): accept numeric UNIT3D byte and ratio fields - #11
Merged
Conversation
UNIT3D deployments disagree about the JSON types of these fields. Seed Pool
and DarkPeers return formatted strings ("1.5 TiB", "2.31"). Blutopia returns
bare numbers:
{"uploaded":53687091200,"downloaded":1073741824,"ratio":50,
"buffer":133143986176,"seedbonus":"200001.00","hit_and_runs":0}
parseBytes() opened with formatted.trim(), so the numeric shape threw
"formatted.trim is not a function". That surfaced in the UI as a bare
"tracker test failed", which reads like a rejected API key and sends you
looking at credentials instead of at the response body.
parseBytes now takes string | number, truncating fractional counts and
rejecting negatives the same way the string path does. The response
interface widens to unions, and ratio/seedbonus go through a toNumber()
helper because parseFloat() only accepts a string.
Also records in the Blutopia registry entry that its IRC network is retired
in favour of Matrix, so autobrr has no network to connect to; the tracker's
client blacklist; the connectability requirement; and the PID exposure and
ratio risk in its RSS feeds.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Knip Code AnalysisFound 9 total issues
View details
Use |
|
🚫 Security audit failed Critical Failures
Warnings
Passed (36/38)
Summary: 36/38 checks passed See |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Adding Blutopia failed with a bare
tracker test failed, which reads like a rejected API key. The real error, only visible in the container log, was:UNIT3D deployments disagree about the JSON types of these fields. Seed Pool and DarkPeers return formatted strings. Blutopia returns bare numbers:
{"username":"...","group":"User","uploaded":53687091200,"downloaded":1073741824, "ratio":50,"buffer":133143986176,"seeding":0,"leeching":0, "seedbonus":"200001.00","hit_and_runs":0}parseBytes()opened withformatted.trim(), so the numeric shape threw immediately. Noteseedbonusis a string in the same response whileratiois a number, so this is not a simple "one site is numeric" split — the shapes are mixed within a single payload.The fix
parseBytesnow acceptsstring | number. The numeric path truncates fractional counts, since a fractional byte is meaningless andBigInt()throws on a non-integralNumber, and it rejects negatives exactly as the string path does. Non-finite input returns0nrather than throwing insideBigInt().Unit3dApiResponsewidens the affected fields to unions, andratio/seedbonusgo through a smalltoNumber()helper, becauseparseFloat()only accepts a string.The string path is untouched.
Why this was worth more than a coercion at the call site
Coercing in the adapter would have fixed Blutopia and left the next UNIT3D site to rediscover it. The type union documents that both shapes are legitimate UNIT3D.
Also in here
The Blutopia registry entry gains four things from a fresh read of the site's rules:
blu-announceis the upload feed. This matters operationally: autobrr ships no Blutopia definition and searching for one is a dead end, because the network it would connect to no longer exists.The existing Hit & Run and Account Pruning sections were checked against the current rules and are accurate, so they are unchanged.
Tests
5 new cases in
parser-numeric-bytes.test.tsusing the exact values Blutopia returned, plus the string path, truncation, negatives and non-finite input. Typecheck and biome clean. 2951 passing; the single failure inchart-transforms.test.tsis pre-existing onmainand unrelated.🤖 Generated with Claude Code