mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-12-03 11:22:51 +08:00
Merge the reviewed music-account changes into playback retry
This commit is contained in:
commit
d34e249f8a
27 files changed
+3567
-392
No files matched your search
@@ -465,6 +465,27 @@ export class BiliBiliProvider implements MusicProvider {
|
||||
this.cookie = normalizeCookie(cookie);
|
||||
}
|
||||
|
||||
/**
|
||||
* A view of the same provider logged in as another account (#164 follow-up):
|
||||
* a web user's own B站 login instead of the bot's shared one. Mirrors
|
||||
* NeteaseProvider.withCookie so the web layer can treat every platform the
|
||||
* same way.
|
||||
*
|
||||
* The anonymous buvid3 identity and the WBI signing key are carried over —
|
||||
* both are account-independent caches, and re-fetching them per request would
|
||||
* add two extra round-trips to every search.
|
||||
*/
|
||||
withCookie(cookie: string): BiliBiliProvider {
|
||||
const view = new BiliBiliProvider();
|
||||
view.quality = this.quality;
|
||||
view.buvidCookie = this.buvidCookie;
|
||||
view.buvidInitialized = this.buvidInitialized;
|
||||
view.wbiMixinKey = this.wbiMixinKey;
|
||||
view.wbiKeyFetchedAt = this.wbiKeyFetchedAt;
|
||||
view.setCookie(cookie);
|
||||
return view;
|
||||
}
|
||||
|
||||
getCookie(): string {
|
||||
return this.cookie;
|
||||
}
|
||||
|
||||
@@ -471,6 +471,27 @@ export class KugouProvider implements MusicProvider {
|
||||
return this.quality;
|
||||
}
|
||||
|
||||
/**
|
||||
* A view of the same provider logged in as another account (#164 follow-up):
|
||||
* a web user's own 酷狗 login instead of the bot's shared one.
|
||||
*
|
||||
* Kugou signs every request with the device identity (guid/mid) and binds the
|
||||
* session token to it, so the view MUST reuse this instance's device instead
|
||||
* of generating a fresh one — otherwise the installed cookie is rejected as
|
||||
* coming from an unknown device.
|
||||
*/
|
||||
withCookie(cookie: string): KugouProvider {
|
||||
const view = new KugouProvider();
|
||||
view.guid = this.guid;
|
||||
view.mid = this.mid;
|
||||
// Share the in-flight dfid registration: it is device-scoped, not account-
|
||||
// scoped, and sharing avoids a duplicate /register/dev per request.
|
||||
view.dfidPromise = this.dfidPromise;
|
||||
view.quality = this.quality;
|
||||
view.setCookie(cookie);
|
||||
return view;
|
||||
}
|
||||
|
||||
// --- Shared signed request pipeline (mirrors util/request.js) --------------
|
||||
private async request(opts: {
|
||||
method: "GET" | "POST";
|
||||
|
||||
@@ -217,6 +217,14 @@ export interface MusicProvider {
|
||||
* local files, Jellyfin) omit this and the caller keeps its single attempt.
|
||||
*/
|
||||
getFallbackQualities?(): string[];
|
||||
/**
|
||||
* A view of this same provider logged in as another account, without
|
||||
* disturbing the shared instance. Implemented by the sources that support
|
||||
* per-account logins — NetEase since #164, QQ / Kugou / Bilibili following in
|
||||
* the #164 follow-up. The rest simply omit it and the web layer falls back to
|
||||
* the shared login (see web/api/provider-scope.ts).
|
||||
*/
|
||||
withCookie?(cookie: string): MusicProvider;
|
||||
getPersonalFm?(): Promise<Song[]>;
|
||||
getDailyRecommendSongs?(): Promise<Song[]>;
|
||||
getUserPlaylists?(): Promise<Playlist[]>;
|
||||
|
||||
@@ -838,6 +838,20 @@ export class QQMusicProvider implements MusicProvider {
|
||||
this.radarPage = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* A view of the same provider logged in as another account (#164 follow-up):
|
||||
* a web user's own QQ 音乐 login instead of the bot's shared one.
|
||||
*
|
||||
* The per-user view points at the SAME API server (`this.api.defaults.baseURL`)
|
||||
* — only the cookie differs, so the shared login keeps its own instance.
|
||||
*/
|
||||
withCookie(cookie: string): QQMusicProvider {
|
||||
const view = new QQMusicProvider(this.api.defaults.baseURL ?? "");
|
||||
view.quality = this.quality;
|
||||
view.setCookie(cookie);
|
||||
return view;
|
||||
}
|
||||
|
||||
getCookie(): string {
|
||||
return this.cookie;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { isAxiosError } from "axios";
|
||||
|
||||
/** Axios errors can include music-account cookies in the message or config. */
|
||||
export function musicRequestError(error: unknown): Error {
|
||||
if (isAxiosError(error)) {
|
||||
const status = error.response?.status;
|
||||
return new Error(typeof status === "number" ? `Music service request failed (HTTP ${status})` : "Music service request failed");
|
||||
}
|
||||
return error instanceof Error ? error : new Error("Music service request failed");
|
||||
}
|
||||
Reference in new issue
Block a user