Skip to content

Add M-Team metafile download through the signed link - #27

Merged
tonycoder-hub merged 1 commit into
mainfrom
feat/mteam-metafile-download
Oct 16, 2026
Merged

tonycoder-hub merged 1 commit into
mainfrom
feat/mteam-metafile-download

Conversation

@tonycoder-hub

Copy link
Copy Markdown
Owner

Summary

M-Team serves a .torrent only through a signed link: POST /api/torrent/genDlToken returns it, and fetching it may redirect once. This adds a linked metafile route for that flow. The direct contract TJUPT uses is unchanged.

Route mteam.download_by_token.v1:

  1. POST /api/torrent/genDlToken (API key, form field id). The link is accepted only if it is HTTPS, on an M-Team host, at /api/rss/dlv2, and signed for exactly the requested ID.
  2. A 3 s pause, then one GET of the link on a fresh credential-free client bound to the link's host.
  3. Only for a 3xx to an HTTPS m-team.cc/m-team.io host on the default port: one more GET on another such client. These targets stop as redirect_rejected without ever being contacted: another host, a lookalike domain, an explicit port, http:, magnet:, or a second redirect.

Supporting changes:

  • Link secrecy. httpguard.SecretLink and GetLinkOnce carry the signed link and the redirect target. Both redact themselves when formatted and never appear in errors, reports, or records.
  • Accounting. MaxRequests stays 1 and still means the metafile GET. The token request and a redirect hop are counted in the new LinkRequestsAttempted, bounded by the new MaxLinkRequests (2). RedirectsFollowed stays 0. The CLI accepts a success only when requests_made == 1 + link_requests_attempted. The sealed binding record validates the same bound.
  • Refusals. M-Team answers refusals as HTTP 200 JSON. The not-found message maps to not_found; the per-torrent daily limit, request bursts, code 4, and HTTP 429 map to rate_limited.

Deliberate public changes

  • New capability. mteam now declares torrent.metafile.read_effectful, so site list shows a capability count of 5 for it.
  • New flag and help. site metafile fetch accepts --api-key-stdin. The usage line is now ptctl site metafile fetch (--cookie-stdin | --api-key-stdin) .... Help text gains a section on direct and linked routes and a "Credentials" section.
  • Credential errors. The command now names the required credential flag before reading stdin, e.g. --api-key-stdin is required; ... for mteam. These are new messages: --cookie-stdin and --api-key-stdin are mutually exclusive, and site %q does not support %s authentication.
  • New JSON fields. limits.max_link_requests and used.link_requests_attempted are added and omitted for direct routes. TJUPT JSON, human output, and sealed records are byte-identical.
  • Linked-route report. A linked route reports:
    • scope site_link_requests_then_one_remote_metafile_get;
    • evidence basis effectful_site_issued_link_get_for_remote_id;
    • two extra warnings: the link is a secret, and link requests may count as downloads;
    • LINK REQUEST LIMIT and LINK REQUESTS USED lines in the table output.
  • New stop reason. not_found is now a public metafile stop reason.

Live verification

The account is in its newbie-task period, so no real torrent was downloaded. The route was exercised only against IDs with no torrent:

  • genDlToken signs a link even for a nonexistent ID. That link points at api2.m-team.cc.
  • The link GET for that ID answers HTTP 200 JSON code 1 with the not-found message. That answer motivated reading not_found at the link step. ptctl site metafile fetch --api-key-stdin ... mteam 99999999 then reported not_found with requests_made 2, and the output contained no link material.
  • A bare credential-free GET of /api/rss/dlv2 answers JSON 參數錯誤 with no redirect.
  • The redirect hop for a real torrent is not yet observed live. Whatever host it uses must pass the allowlist, or the fetch stops as redirect_rejected before contacting it.

Reconciliation still reads live site detail with a cookie only.

Tests

  • All fixtures are synthetic: SIGN-CANARY links, a metafile announcing to tracker.invalid, and CANARY keys.
  • New suites cover:
    • the direct link fetch;
    • the one allowed redirect;
    • every rejected redirect shape;
    • token refusals that stop before any link request;
    • link refusals;
    • session budgets;
    • the host allowlist;
    • CLI accounting for 1–2 link requests, and rejection of inconsistent accounts;
    • credential-flag checks before stdin is read;
    • canonical API-key input.
  • Local gate: gofmt, go vet ./..., go test -race ./..., go build -trimpath ./cmd/ptctl.

Docs updated: MTEAM_ADAPTER (new "Metafile download" section), ADDING_A_SITE gaps table, FEATURES, ARCHITECTURE B1, THREAT_MODEL, AUTOMATION, guide/metafiles, guide/sites, and both READMEs.

🤖 Generated with Claude Code

M-Team serves a .torrent only through a signed link: genDlToken returns it,
and fetching it may redirect once. Add a linked metafile route for that flow
without widening the direct contract TJUPT uses.

- site: NewLinkedMetafileFetchConfig declares a linked route. The new
  MaxLinkRequests limit and LinkRequestsAttempted usage count the requests
  before the one metafile GET; MaxRequests still means that GET and
  RedirectsFollowed stays 0. Both fields are omitempty, so TJUPT reports and
  sealed binding records keep their exact bytes, and Record.Validate bounds
  the link count.
- httpguard: SecretLink holds a signed URL that redacts itself when formatted,
  and GetLinkOnce sends one credential-free GET of it, reporting a redirect
  target only when the caller approves it.
- mteam: route mteam.download_by_token.v1 POSTs genDlToken, accepts only an
  HTTPS dlv2 link on an M-Team host signed for the requested ID, pauses 3s,
  GETs it on a fresh client bound to that host, and follows one redirect only
  to an HTTPS m-team.cc or m-team.io host on the default port. Not-found,
  daily-limit, and burst refusals map to not_found and rate_limited.
- cli: site metafile fetch accepts --api-key-stdin, names the required
  credential flag before reading stdin, and reports the link accounting,
  linked scope, evidence basis, and warnings. not_found joins the public stop
  reasons.

Live, the route was exercised only against IDs with no torrent: genDlToken
signs a link for any ID, so not_found is read from the link's JSON answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tonycoder-hub
tonycoder-hub merged commit 37640fc into main Oct 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant