mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat(fm): let each web user link their own NetEase account for personal FM (#164)
With several people sharing one bot, personal FM always followed the one account the bot was logged in with. Each signed-in (non-guest) web user can now scan a QR code under Settings → 账户 to link their own NetEase account; FM they start from the WebUI then comes from their account. - user_music_cookies table (per user + platform, dropped with the user). - NeteaseProvider.pollQrLogin returns the cookie without storing it, so a personal login can never replace the bot's shared account; checkQrCodeStatus is now built on it. withCookie gives a view bound to another account. - /api/me/music/netease: status / qrcode / qrcode/status / unlink, acting only on req.user. The cookie never leaves the server. - POST /api/player/:botId/fm uses the caller's linked account for NetEase. Songs still resolve through the shared provider when played. TeamSpeak chat !fm keeps using the shared account: chat users are not tied to web accounts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8ff51ea6e0
commit
ac4a12d8bd
11 files changed
+652
-11
No files matched your search
@@ -139,3 +139,48 @@ describe("NeteaseProvider.search pagination", () => {
|
||||
expect(callByType(get, 10).offset).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("NeteaseProvider per-user login (#164)", () => {
|
||||
function withGet(p: NeteaseProvider, impl: (path: string, cfg: any) => any) {
|
||||
const get = vi.fn(async (path: string, cfg: any) => ({ data: impl(path, cfg) }));
|
||||
(p as any).api = { get, defaults: { baseURL: "http://127.0.0.1:3001" } };
|
||||
return get;
|
||||
}
|
||||
|
||||
it("pollQrLogin returns the cookie without touching the shared account", async () => {
|
||||
const p = new NeteaseProvider("http://127.0.0.1:3001");
|
||||
p.setCookie("MUSIC_U=shared");
|
||||
withGet(p, () => ({ code: 803, cookie: "MUSIC_U=personal" }));
|
||||
expect(await p.pollQrLogin("k")).toEqual({ status: "confirmed", cookie: "MUSIC_U=personal" });
|
||||
expect(p.getCookie()).toBe("MUSIC_U=shared");
|
||||
});
|
||||
|
||||
it("pollQrLogin maps the waiting / scanned / expired codes", async () => {
|
||||
const p = new NeteaseProvider("http://127.0.0.1:3001");
|
||||
let code = 801;
|
||||
withGet(p, () => ({ code }));
|
||||
expect(await p.pollQrLogin("k")).toEqual({ status: "waiting" });
|
||||
code = 802;
|
||||
expect(await p.pollQrLogin("k")).toEqual({ status: "scanned" });
|
||||
code = 800;
|
||||
expect(await p.pollQrLogin("k")).toEqual({ status: "expired" });
|
||||
});
|
||||
|
||||
it("checkQrCodeStatus still stores the cookie on the shared provider (admin login)", async () => {
|
||||
const p = new NeteaseProvider("http://127.0.0.1:3001");
|
||||
withGet(p, () => ({ code: 803, cookie: "MUSIC_U=admin" }));
|
||||
expect(await p.checkQrCodeStatus("k")).toBe("confirmed");
|
||||
expect(p.getCookie()).toBe("MUSIC_U=admin");
|
||||
});
|
||||
|
||||
it("withCookie gives a view that fetches FM with the other account's cookie", async () => {
|
||||
const p = new NeteaseProvider("http://127.0.0.1:3001");
|
||||
p.setCookie("MUSIC_U=shared");
|
||||
const personal = p.withCookie("MUSIC_U=personal");
|
||||
const get = withGet(personal, () => ({ data: [] }));
|
||||
await personal.getPersonalFm();
|
||||
expect(get.mock.calls[0][1].params.cookie).toBe("MUSIC_U=personal");
|
||||
expect(p.getCookie()).toBe("MUSIC_U=shared");
|
||||
expect(personal.platform).toBe("netease");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user