* Add configurable NetEase real IP in web settings
* Match NetEase playback User-Agent to cookie platform
* fix(netease): keep playback UA aligned with cookie profile
---------
Co-authored-by: TIANYAO ZHANG <88520881+ZHANGTIANYAO1@users.noreply.github.com>
`import-shared` read the cookie from qq.json, which is only the on-disk
copy. After #188 renews credentials through the managed session that file
goes stale, so this route would seed the pool with a dead cookie.
Prefer the running QQ provider's in-memory cookie and fall back to the
cookie store when no QQ provider is mounted (tests that only register
netease keep the old behaviour). Two regressions: the rotated cookie wins
over the file copy, and a provider without a login 409s instead of
creating a dead row.
The account radio only governs the browser player (search, playlists, the
embedded preview). Playback inside the TeamSpeak room — a web-queued song, a
`!play` from chat, auto-advance — resolves through the bot's injected provider,
which is the shared login, unconditionally.
That is the intended design: membership is shared, library isolation is not.
A member without VIP still gets to hear paid tracks in the channel; they just
do not get their own recommendations in the web UI.
It was not obvious from the UI, though. "共享账号(管理员的)" reads like a
channel-wide switch, and a member who picked it would expect their play history
to land on the admin account everywhere — which it does, but for an unrelated
reason. Two notes now say so: one in the admin feature hint (what the toggle
does and does not affect), one under the member radio (that it is web-only).
The order was hardcoded: own account → assigned account → shared. That is the
right default (privacy first), but it leaves one common case stuck: a member's
own NetEase login is real but has no membership, while the admin's does. They
linked their account, so playback keeps using theirs, and every paid track
fails — with no way to say "just use the admin's for playback".
Two things now:
1. An explicit choice — `user_music_prefs` (userId + platform), exposed as
GET/PUT `/api/me/music/:platform/preference` and a radio in the account
card. `preferShared: true` outranks EVERYTHING, including `alwaysPersonal`
(someone who chose membership over their own recommendations wants the
shared login for FM too). It stores a flag, not a cookie — flipping it back
restores the personal account untouched.
2. An automatic fallback for people who never touch the switch. Only
`getSongUrl` is wrapped: if the personal account returns `url: null` or
throws, the same track is retried once on the shared login. Search,
playlists and FM stay on the member's own account — that is the point of
per-user logins, and widening the fallback would leak their library back to
the admin's.
Details:
- The fallback lives in `resolveProviderForRequest`, so every playback entry
point (web click, chat !play, auto-advance, playlists) gets it by
construction, and the shared instance is never mutated.
- `fallbackToShared: false` is available for callers that must stay strictly on
the member's account; the default is on, because "my account has no VIP" is
the complaint that produced this feature.
- The status payload now carries `preferShared` and `featureEnabled`, so the UI
can render the radio without a second round-trip and hide it when the admin
has the feature off (PUT answers 409 in that case).
13 new tests: preference overrides own + assigned + alwaysPersonal, feature-off
ignored, GET/PUT round-trip, per-platform isolation, stored cookie untouched,
non-boolean rejected, 409 when disabled; fallback on null, on throw, keeps the
personal result when it works, can be disabled, leaves the shared instance
untouched.
A cookie file on a live deployment held this:
MUSIC_A_T=1456043741268; Max-Age=2147483647; Expires=Thu, 25 Nov 2094 ...;
Path=/api/clientlog;;MUSIC_R_T=...; Max-Age=...; Path=/eapi/feedback; ...
That is a `Set-Cookie` header pasted whole. The cookie is then handed to the
sidecar as `?cookie=<the whole thing>`, so `Max-Age`, `Expires` and `Path` are
read as cookie NAMES and the string grows to several KB before URL-encoding.
Measured on that box (data/logs/bot.log):
- 34 of 34 `/song/url/v1` calls failed with `ERR_BAD_REQUEST` (HTTP 400);
- the same failure is still happening today, e.g. 17:14 and 17:20 local;
- every one surfaced to the user as 「无法播放(区域/版权限制)」.
So the message people were chasing for weeks is not a copyright signal at all
— it is the sidecar rejecting a malformed request.
`normalizeCookie()` drops attribute pairs, the `Set-Cookie:` prefix, CR/LF and
duplicate names, and keeps only real `name=value` pairs. It is applied:
- on `save()`, so nothing malformed reaches the file again;
- on `load()`, and **written back when it differs** — an existing deployment is
repaired in place without asking anyone to scan a QR code again;
- in `setCookie()` of all four providers, including Kugou, which parses into a
map and would otherwise store `max-age` as a device field.
jellyfin is excluded: its blob is JSON (accessToken/userId/deviceId), not a
cookie header, and normalising it would shred the payload. A test pins that.
Valid cookies are untouched — `normalizeCookie` is idempotent and byte-exact on
a clean string, and a clean file is not rewritten.
This does not overlap with the play-URL retry PR: that one retries a genuine
`url: null`, this one stops the request from being rejected before it is sent.
Both are needed — retrying a 400 just gets four more 400s.
Sharing one login between members mixes their playback history and
recommendations, which is almost never what an admin means by handing out an
account. Keep 0 (= unlimited) available, but not as the default.
Every member saw the admin's library: the bot keeps one shared login per
platform (data/cookies/<platform>.json) and search, playlists and playback
URLs all read through it. #164 added a personal NetEase login, but only for
私人FM — the rest still came from the shared account.
On top of that, most members do not own a paid login, so "everyone links their
own" is not enough: the admin has to be able to hand out accounts.
What this adds, behind one admin switch (`perUserMusicAccounts`, default off):
- One login per request, resolved in this order: the caller's OWN linked
account, then an account an admin ASSIGNED, then the bot's shared login.
- An admin-owned pool (`music_accounts`) plus per-member assignments
(`music_account_grants`, PK userId+platform = one per platform). Assignments
are capacity-checked inside a transaction, so an exclusive account cannot be
handed to two members by two concurrent clicks. `enabled = 0` is an instant
rollback of every grant without deleting them.
- Own-beats-assigned, and the two live in separate tables: a member scanning
their own QR code never overwrites an admin's assignment, and unlinking on
the member side never revokes what the admin granted.
- QQ / Kugou / Bilibili now implement `withCookie`, so all four sources can be
isolated. Only NetEase exposes QR self-linking (it is the only one with
`pollQrLogin`); the rest accept an assigned account, which is the workflow
that actually matters for members without a paid login.
- `/api/music-accounts` is admin-only (`requireAdmin`, not `bot.manage`):
members must never see which account was handed to whom. Cookies are masked
in every response.
Switch off = no behaviour change at all, except 私人FM keeps the #164 behaviour
through `alwaysPersonal`.
Upstream a0f0b49..6f165b5 added the pause/resume fade tail but shipped no
test updates, leaving 5 assertions red (also reproducible on pristine
upstream/main, so not merge-induced).
- instance-recovery/instance harnesses: stub players borrow
AudioPlayer.prototype.pause/resume, which now call this.setTransportRamp().
Give the stubs that method or they throw TypeError on pause/resume.
- voice-failure: pausing deliberately emits a fade tail, so the frame count
no longer freezes at exactly 50. Assert the de-click fade completes, then
that the scheduler and elapsed clock are genuinely frozen — the actual
behavior under test.
No production code changed.
Co-Authored-By: Claude Code <noreply@anthropic.com>