Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ capabilities at the edge, not assumptions in the core domain model.
bonus exchange (confirmed with the account password from a stdin bundle),
and password login with an optional two-step code that issues the session
cookie;
and an experimental M-Team adapter with session, account, search, and
detail reads plus acknowledged metafile fetch through the official API and a
site-issued API key.
and an experimental M-Team adapter with session, account, search, detail,
and bonus reads plus acknowledged metafile fetch and at-most-once bonus
exchange through the official API and a site-issued API key.
- **Downloaders:** qBittorrent and Transmission reads, plus reviewed stopped
adoption, recheck/start, stop, and keep-data removal of one exact job.
- **Reconciliation:** one report that keeps site, downloader, metafile, and
Expand Down
11 changes: 6 additions & 5 deletions docs/ADDING_A_SITE.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,23 +269,24 @@ and do it in a separate behavior-preserving commit.
| NexusPHP forks, including TJUPT | Cookie sessions match `cookie_header`, and HTML responses match the existing ports. | Page recognition and parsers for that fork, with synthetic fixtures. Forks differ, so do not assume TJUPT's pages. |
| Unit3D | Cookie-session web pages fit. | Using its token-authenticated API instead runs into the gaps below. |
| Gazelle-based trackers | Cookie sessions fit; their JSON responses need a JSON parser rather than HTML recognition. | Where an API key replaces the session cookie, the gaps below apply. |
| M-Team | Status, account, search, detail, the signed-link metafile download, and live-site reconciliation are implemented in `internal/site/mteam` over the JSON API with an API key. | Bonus commands: the open gaps below. |
| M-Team | Status, account, search, detail, the bonus shop catalog, review, and exchange, the signed-link metafile download, and live-site reconciliation are implemented in `internal/site/mteam` over the JSON API with an API key. | RSS, seeding lists, and messages are not implemented. |

## Gaps for API-token sites

These are the places that assumed a cookie, HTML, or a single origin. The
M-Team adapter closed what its four reads and its download needed; the rest is
M-Team adapter closed what its reads, its download, and its bonus exchange
needed; the rest is
design work for whichever pull request first needs it. Each open item changes a public contract
or a security control, so it needs its own review.

| Gap | Status | Where | What is left |
|---|---|---|---|
| Only one auth method existed | Done | `domain.AuthMethodAPIKeyHeader` (`api_key_header`); `knownAuthMethod` in `internal/site/descriptor.go` | Nothing. |
| Credential input was cookie-only | Partly done | `--api-key-stdin` and `readAPIKeyCredential` in `internal/cli` serve `site status`, `account`, `search`, and `detail`; `site metafile fetch` reads it with `readEffectfulAPIKeyCredential`; `reconcile` takes `--site-api-key-stdin`, `--site-live`, and the bundle's `site_api_key` | Bonus commands still take cookies only. |
| The CLI gated on cookies | Partly done | `siteRead` in `internal/cli/site.go`, `site detail`, `site metafile fetch`, and `reconcile` check the method the caller chose | Two `SupportsAuth(domain.AuthMethodCookieHeader)` checks remain, in `site_bonus.go` and `site_bonus_exchange.go`. |
| Credential input was cookie-only | Done | `--api-key-stdin` and `readAPIKeyCredential` in `internal/cli` serve `site status`, `account`, `search`, `detail`, `bonus-catalog`, and `bonus review`; `site metafile fetch` and `site bonus exchange submit` read it with `readEffectfulAPIKeyCredential`; `reconcile` takes `--site-api-key-stdin`, `--site-live`, and the bundle's `site_api_key` | Nothing. The `--credential-bundle-stdin` of `site bonus exchange submit` still carries a cookie, because only TJUPT confirms an exchange with the password. |
| The CLI gated on cookies | Done | Every site command picks the method with `siteCredentialSourceFor` and checks that the site supports it | Nothing. |
| The transport only sent `Cookie` | Done | `httpguard.NewWithHeaderCredential` binds one validated, non-reserved header | Nothing. |
| Redaction did not know the header | Done | `security.Redact` covers `x-api-key` header lines and `apiKey`-style fields | Nothing. |
| No JSON requests | Done | `httpguard.Client.PostReadOnce`: one bounded, non-replayable POST with no redirect and no retry, covered in the threat model | Nothing for reads. Effectful API calls still need their own acknowledged port. |
| No JSON requests | Done | `httpguard.Client.PostReadOnce`: one bounded, non-replayable POST with no redirect and no retry, covered in the threat model; `PostEffectOnce` sends the same POST for an acknowledged write, such as the M-Team bonus exchange, and says so in its `User-Agent` | Nothing. |
| One origin per site | Done | The API origin is the descriptor `BaseURL`; a signed link and its one redirect may reach only hosts the adapter allowlists (`siteHost` in `internal/site/mteam/metafile.go`), each on a fresh credential-free client | A new site's allowlist needs the same review before its hosts are contacted. |
| The download is two requests | Done | `site.NewLinkedMetafileFetchConfig` declares a linked route; `MetafileFetchLimits.MaxLinkRequests` and `MetafileFetchUsage.LinkRequestsAttempted` count the requests before the one metafile `GET`, and the sealed record checks them; `httpguard.SecretLink` and `GetLinkOnce` keep the signed URL secret | Nothing. Both fields are omitted for direct routes, so TJUPT records are unchanged. See [MTEAM_ADAPTER.md](MTEAM_ADAPTER.md#metafile-download). |
| Site-specific CLI text | Done | `detailRouteWarnings` in `internal/cli/site_detail.go` keys the `site detail` warning by route ID; an unlisted route gets only the generic sentence | Add a sentence there when a new detail route has something specific to say. |
15 changes: 9 additions & 6 deletions docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ deliberately does not. For step-by-step usage, see the
remain site claims only;
- an explicitly acknowledged, durable bonus-exchange state machine (TJUPT
confirms each exchange with the account password, read with the cookie from
one strict stdin bundle and sent in the same single POST):
one strict stdin bundle and sent in the same single POST; M-Team exchanges
one unit of goods that take no input with the API key alone):
private reviewed intent, fresh exact-option re-observation, deterministic
no-clobber attempt marker, at most one non-retried POST, and a separately
sealed confirmed/rejected/unknown outcome; its credential-free bounded
Expand Down Expand Up @@ -111,11 +112,13 @@ deliberately does not. For step-by-step usage, see the
shown, acknowledgement flags are still required, account passwords are never
saved, and `site logout SITE` deletes the file;
- an experimental M-Team session check, account snapshot (username, uploaded
and downloaded bytes, ratio, and bonus), first-page torrent search with
seeders, leechers, promotion factors, and category names, and torrent detail
for one remote ID, through one read-only POST per invocation to the official
JSON API, authenticated by a site-issued API key saved by `site login` or
piped on stdin, with no redirect, proxy, or retry;
and downloaded bytes, ratio, and bonus), torrent search by page, mode,
category, and free promotion with seeders, leechers, promotion factors, and
category names, torrent detail for one remote ID, and a bonus-shop catalog
and exact-goods review, through read-only POSTs to the official JSON API (one
per invocation; the catalog reads the balance and the shop on one client),
authenticated by a site-issued API key saved by `site login` or piped on
stdin, with no redirect, proxy, or retry;
- an explicitly acknowledged M-Team metafile fetch for one remote ID: one
token POST for a signed download link, one credential-free GET of that link,
and at most one further GET only for a redirect to an M-Team HTTPS host, with
Expand Down
80 changes: 73 additions & 7 deletions docs/MTEAM_ADAPTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
M-Team (馒头PT, TP :: mTorrent) is the second experimental site and the first
that uses a site-issued API key instead of a session cookie. The adapter talks
only to M-Team's own hosts, starting at the official JSON API at
`https://api2.m-team.cc`, and declares four reads and one acknowledged
download:
`https://api2.m-team.cc`, and declares six reads and two acknowledged
effects:

- session check (`site status`);
- account snapshot (`site account`);
- torrent search (`site search`), with category names;
- torrent detail (`site detail`);
- bonus shop catalog (`site bonus-catalog`) and one-offer review (`site bonus
review`);
- metafile download (`site metafile fetch`), which is tracker-visible and needs
`--acknowledge-site-effect`; see [Metafile download](#metafile-download).
`--acknowledge-site-effect`; see [Metafile download](#metafile-download);
- bonus exchange (`site bonus exchange submit`), which spends bonus and needs
`--acknowledge-bonus-exchange`; see [Bonus shop](#bonus-shop).

The reads were smoke-tested live on 2026-10-16 with a newly created API key:
`site status` reported `authenticated`, `site account` read the profile, `site
Expand Down Expand Up @@ -51,6 +55,8 @@ ptctl site search mteam "Ubuntu"
ptctl site search --output json mteam "Ubuntu"
ptctl site search --page 2 --category 419,439 --free mteam "Ubuntu"
ptctl site detail mteam REMOTE_ID
ptctl site bonus-catalog mteam
ptctl site bonus review mteam OPTION
ptctl site metafile fetch --acknowledge-site-effect --metafile-store "$PTCTL_STORE" mteam REMOTE_ID
```

Expand All @@ -76,16 +82,19 @@ sent. `--cookie-stdin` is refused because the adapter does not accept cookies.

## Requests

Each read sends exactly one request and never retries (the download takes more;
see [Metafile download](#metafile-download)):
Each read sends exactly one request and never retries, except `bonus-catalog`,
which sends two on one connection (the download takes more; see [Metafile
download](#metafile-download)):

| Command | Request | Body |
|---|---|---|
| `site status`, `site account` | `POST /api/member/profile` | an empty `multipart/form-data` form |
| `site search` | `POST /api/torrent/search` | `{"mode":"normal","keyword":QUERY,"pageNumber":1,"pageSize":50}`; the options below add `categories` and `discount` and change `mode` and `pageNumber` |
| `site detail` | `POST /api/torrent/detail` | a `multipart/form-data` form with the one field `id` |
| `site bonus-catalog` | `POST /api/member/profile`, then `POST /api/mall/list` | an empty `multipart/form-data` form each |
| `site bonus review` | `POST /api/mall/list` | an empty `multipart/form-data` form |

The API exposes these reads as POST requests. All three endpoints only read;
The API exposes these reads as POST requests. All five endpoints only read;
the reads send no other endpoint. In particular, `site detail` never calls
`/api/torrent/viewHits`, which the website's own detail page calls to count a
view. The request uses the same strict transport as every
Expand Down Expand Up @@ -273,9 +282,66 @@ with `site_api_key` in place of `site_cookie`. The read is the one
`/api/torrent/detail` request above; it never asks for a signed download link.
See [Reconciliation](guide/reconcile.md).

## Bonus shop

M-Team sells goods for bonus (魔力值) in its shop (商城). `site bonus-catalog
mteam` reads the balance from the profile and the goods from `/api/mall/list`,
one row per goods ID. The option is the goods ID; the columns are the name, the
goods type, the price, and a status:

| Goods type | Example | Status |
|---|---|---|
| `UPLOAD` | 上传量, priced per GB | `available` |
| `INVITE` | an invitation | `available` |
| `TITLE`, `GLOBAL_FREE_SINGLE`, `GLOBAL_FREE_POOL` | a custom title, a site-wide free promotion | `available, requires input` |
| any other type, such as `INVITE_BUY_BONUS` | selling an invitation back | `unknown` |

Goods the shop marks off the shelf (`shelf` is `NO`) are `disabled`; goods
with any other shelf value, or limited to some roles, are `unknown`. The name is the
simplified-Chinese name the API returns (which the site sometimes writes in
traditional script), else the traditional or English one. A shop answer that is
empty, repeats a goods ID, or holds goods without a canonical ID, type, name, or
price fails the whole catalog instead of returning a partial one.

`site bonus review mteam OPTION` reads the shop once more and reports one goods
item as an offer review (route `mteam.mall_list_review.v1`). The balance is not
part of the review, so the review ID changes only when the goods item does,
such as when its price changes. The review accounting maps the JSON answer onto
the shared limits: each goods item counts as one form, each of its members as
one field, and each JSON token as one token.

**Exchange.** `site bonus exchange submit` follows the same prepare, submit,
and status workflow as TJUPT (see [the sites guide](guide/sites.md)), with the
saved API key and no password. After one fresh review it sends one
`POST /api/mall/exchange` (route `mteam.mall_exchange_post.v1`) with the form
fields `goodsId` and `num`, where `num` is always `1`: one unit, so one GB of
upload credit or one invitation. Only goods that are `available` and need no
input can be exchanged; for the rest the fresh review stops as
`submission_form_unavailable` and nothing is sent. The POST identifies itself
as an explicit-effect client in its `User-Agent`. The answer is read as:

| Answer | Outcome | `SUBMISSION STOP` |
|---|---|---|
| API code `0` | `confirmed` | none |
| HTTP 401, or API code `401` | `rejected` | `server_authentication_rejected` |
| HTTP 429, or API code `4` | `rejected` | `server_rate_limited` |
| Any other API code, such as too little bonus or a shop limit | `rejected` | `server_refused` |
| Any other status, a body that is not JSON, or a cut-off answer | `unknown` | `submission_response_unrecognized` |

A rejected exchange spends nothing. An `unknown` one may have spent bonus, is
never retried, and is checked on the site's own bonus log. The shop's own
limits, such as the upload-credit cap tied to share ratio, are enforced by the
site, not by ptctl.

**Live check.** On 2026-10-16 `site bonus-catalog` and `site bonus review mteam
1` were run live: the catalog listed the six goods above with the balance, and
the review completed in one request. `site bonus exchange submit` has not been
run live, because the test account's balance was below the cheapest goods
item; it is covered by synthetic tests only.

## Not supported yet

Bonus exchange, RSS, seeding lists, and messages are not implemented.
RSS, seeding lists, and messages are not implemented.

## Fixtures

Expand Down
20 changes: 15 additions & 5 deletions docs/THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ session or revoke the key on the site. Account and downloader passwords are
never saved. The file is not encrypted; an OS keyring or credential helper
remains future work (see
[Known gaps](#known-gaps-before-broader-mutation-support)).
The M-Team adapter's reads send at most one bounded POST per command to one of
three read-only JSON API endpoints (`member/profile`, `torrent/search`, and
`torrent/detail`), with a non-replayable body of at most 16 KiB, and never
retry. Its metafile fetch sends one token POST, waits three seconds, and then
The M-Team adapter's reads send bounded POSTs to four read-only JSON API
endpoints (`member/profile`, `torrent/search`, `torrent/detail`, and
`mall/list`), one per command except `bonus-catalog`, which sends `member/profile`
then `mall/list` on one client spaced three seconds apart. Each body is
non-replayable and at most 16 KiB, and nothing is retried. Its metafile fetch sends one token POST, waits three seconds, and then
makes at most two GETs as described above; the site's per-torrent daily
download limit and burst refusals stop it as `rate_limited`. HTTP 429 is terminal. There is no cross-process limiter in the alpha, so
callers must not loop or parallelize site commands. There is no Cloudflare or
Expand All @@ -200,7 +201,8 @@ preserved, never arbitrary cookie, key, URL, header, or response text.
The detail route sends
only the canonical `id`; it deliberately omits NexusPHP's view-counting `hit`
parameter and never follows the download reference found in the page.
Bonus review sends only the one GET and has no POST-capable transport surface.
TJUPT's bonus review sends only the one GET and has no POST-capable transport
surface; M-Team's sends the one read-only `mall/list` POST.
The account projection accepts only the exact authenticated bonus-page route,
valid UTF-8, a bounded username, and a canonical bonus decimal. Optional
fields come only from the page's single user-panel table, and only when every
Expand All @@ -221,6 +223,14 @@ timeout, transport ambiguity, unrecognized response,
or local outcome-write failure is recorded as rejected/unknown when possible
and is never used to justify another automatic request.

On M-Team the fresh review is the one read-only `mall/list` POST and the
submission is one `mall/exchange` POST sent through `PostEffectOnce`, whose
`User-Agent` names an explicit-effect client. The body holds only `goodsId` and
`num`, fixed at `1`, and goods that need user input or are not plainly
available never get one. The API key is the only credential. API code `0` is
confirmed and any other API code is rejected; a status, media type, or body
that is not recognized, or a cut-off answer, is unknown and is not retried.

A site that confirms exchanges with the account password (TJUPT) widens the
secret surface to that password, so its handling is narrower than the cookie's.
It is never saved and never read from argv. With `--credential-bundle-stdin`
Expand Down
16 changes: 10 additions & 6 deletions docs/guide/sites.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ API and never retry; search results add seeders, leechers, promotion, and
category-name columns, and `search` takes `--page N`, `--mode normal|adult`,
`--category ID`, and `--free`. `site metafile fetch` downloads one `.torrent` into the
private store through M-Team's signed link, as described in
[metafiles.md](metafiles.md). Bonus commands are not available for M-Team yet,
and `reconcile` reads live site detail with a cookie only. Setup, results, and
error lines are in [MTEAM_ADAPTER.md](../MTEAM_ADAPTER.md):
[metafiles.md](metafiles.md). `bonus-catalog` and `bonus review` read M-Team's
bonus shop, and `bonus exchange submit` buys one unit of goods that need no
input with the API key alone. `reconcile --site-live` reads live detail with the
saved key. Setup, results, and error lines are in
[MTEAM_ADAPTER.md](../MTEAM_ADAPTER.md):

```bash
ptctl site login mteam
Expand All @@ -174,6 +176,8 @@ ptctl site account mteam
ptctl site search mteam "Ubuntu"
ptctl site search --page 2 --free mteam "Ubuntu"
ptctl site detail mteam REMOTE_ID
ptctl site bonus-catalog mteam
ptctl site bonus review mteam GOODS_ID
printf '%s' "$MTEAM_API_KEY" | ptctl site status --api-key-stdin mteam
```

Expand Down Expand Up @@ -205,9 +209,9 @@ flag, its `submit` uses the saved session cookie and asks for the password on
the terminal with echo off; the password is used for that one exchange and
never saved. Scripts pass the cookie and password together as one strict JSON
bundle on stdin (`--credential-bundle-stdin`), and `--cookie-stdin` is refused;
see the TJUPT example below. A site that needs only the cookie uses the saved
cookie, or takes `--cookie-stdin`. A saved credential never stands in for
`--acknowledge-bonus-exchange`.
see the TJUPT example below. A site that needs only the cookie or API key, such
as M-Team, uses the saved one, or takes `--cookie-stdin` or `--api-key-stdin`.
A saved credential never stands in for `--acknowledge-bonus-exchange`.

To cross that boundary, first initialize a private state store (the same
versioned owner-only store format used by metafile artifacts), review the exact
Expand Down
Loading
Loading