mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-12-03 19:32:51 +08:00
feat(web): artist search, artist pages, and full-catalogue playback
Adds artist support for the NetEase and QQ providers plus the matching UI. Backend: - SearchResult gains `artists`; new optional MusicProvider methods getArtistDetail / getArtistSongs / getArtistAlbums / getArtistAllSongs. - NetEase: /cloudsearch type=100 for artist search, /artists, /artist/songs, /artist/album and /artist/desc for the artist page. - QQ: singer search rides along in the existing musicu.fcg batch (search_type=1); singer detail via music.web_singer_info_svr. QQ exposes no working singer-song paging endpoint, so the full catalogue is built from the hot 50 plus every album of the singer (album search filtered by singerMID, songs fetched per album, de-duplicated, cached for 10 minutes). A failed album sweep is never cached and degrades to the hot list. - API: GET /api/music/artist/:id and POST /api/player/:botId/play-artist (player.control capability, guest flag playCollection); /search/all now aggregates artists too. Frontend: - Search history in localStorage (max 10, per platform, never shared between users), shown as a dropdown under the search box and as 最近搜索 chips. - Artist row in the search results; new /artist/:id page (portrait, aliases, stats, description, top songs, album shelf) with 播放 / 随机播放, which queue the singer's whole catalogue. - playArtist store action. Tests cover the provider mappers, the new routes, the play-artist collector (paging, de-duplication, 500-track cap), permission gating and the new views.
This commit is contained in:
1 parent
87fca6d8b7
commit
b6ad536bb7
17 files changed
+2260
-14
No files matched your search
@@ -503,3 +503,117 @@ describe("music router GET /bilibili/parts", () => {
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe("music router GET /artist/:id", () => {
|
||||
function artistProvider(overrides: Record<string, unknown> = {}): MusicProvider {
|
||||
return {
|
||||
platform: "netease",
|
||||
search: vi.fn().mockResolvedValue(empty),
|
||||
getArtistDetail: vi.fn().mockResolvedValue({
|
||||
id: "6452",
|
||||
name: "Adele",
|
||||
avatarUrl: "http://p/1.jpg",
|
||||
platform: "netease",
|
||||
description: "English singer",
|
||||
}),
|
||||
getArtistSongs: vi.fn().mockResolvedValue([
|
||||
{ id: "1", name: "Hello", artist: "Adele", album: "25", duration: 295, coverUrl: "c", platform: "netease" },
|
||||
]),
|
||||
getArtistAlbums: vi.fn().mockResolvedValue([
|
||||
{ id: "a1", name: "25", artist: "Adele", coverUrl: "c", songCount: 11, platform: "netease" },
|
||||
]),
|
||||
...overrides,
|
||||
} as unknown as MusicProvider;
|
||||
}
|
||||
|
||||
function mount(netease: MusicProvider, qq: MusicProvider = fakeProvider("qq")) {
|
||||
const app = express();
|
||||
app.use("/api/music", createMusicRouter(netease, qq, fakeProvider("bilibili"), pino({ level: "silent" })));
|
||||
return app;
|
||||
}
|
||||
|
||||
it("returns artist detail, hot songs and albums for the requested platform", async () => {
|
||||
const netease = artistProvider();
|
||||
const res = await request(mount(netease)).get("/api/music/artist/6452?platform=netease");
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.artist).toMatchObject({ id: "6452", name: "Adele", description: "English singer" });
|
||||
expect(res.body.songs).toHaveLength(1);
|
||||
expect(res.body.albums).toHaveLength(1);
|
||||
expect(netease.getArtistDetail).toHaveBeenCalledWith("6452");
|
||||
expect(netease.getArtistSongs).toHaveBeenCalledWith("6452");
|
||||
expect(netease.getArtistAlbums).toHaveBeenCalledWith("6452");
|
||||
});
|
||||
|
||||
it("routes to the QQ provider when platform=qq", async () => {
|
||||
const qq = artistProvider({ platform: "qq" });
|
||||
const res = await request(mount(fakeProvider("netease"), qq)).get("/api/music/artist/abc?platform=qq");
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(qq.getArtistDetail).toHaveBeenCalledWith("abc");
|
||||
});
|
||||
|
||||
it("404s when the provider has no such artist", async () => {
|
||||
const netease = artistProvider({ getArtistDetail: vi.fn().mockResolvedValue(null) });
|
||||
const res = await request(mount(netease)).get("/api/music/artist/999");
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body.error).toBe("Artist not found");
|
||||
});
|
||||
|
||||
it("501s when the provider does not support artists at all", async () => {
|
||||
const res = await request(mount(fakeProvider("netease"))).get("/api/music/artist/1");
|
||||
expect(res.status).toBe(501);
|
||||
expect(res.body.error).toBe("Not supported by this provider");
|
||||
});
|
||||
|
||||
it("degrades each leg independently — a failing songs/albums call still returns the hero", async () => {
|
||||
const netease = artistProvider({
|
||||
getArtistSongs: vi.fn().mockRejectedValue(new Error("boom")),
|
||||
getArtistAlbums: vi.fn().mockRejectedValue(new Error("boom")),
|
||||
});
|
||||
const res = await request(mount(netease)).get("/api/music/artist/6452");
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.artist.name).toBe("Adele");
|
||||
expect(res.body.songs).toEqual([]);
|
||||
expect(res.body.albums).toEqual([]);
|
||||
});
|
||||
|
||||
it("tolerates a provider that only implements getArtistDetail", async () => {
|
||||
const netease = artistProvider({ getArtistSongs: undefined, getArtistAlbums: undefined });
|
||||
const res = await request(mount(netease)).get("/api/music/artist/6452");
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.songs).toEqual([]);
|
||||
expect(res.body.albums).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("music router GET /search/all artist aggregation", () => {
|
||||
function searchProvider(platform: MusicProvider["platform"], artists: unknown[]): MusicProvider {
|
||||
return {
|
||||
platform,
|
||||
search: vi.fn().mockResolvedValue({ ...empty, artists }),
|
||||
} as unknown as MusicProvider;
|
||||
}
|
||||
|
||||
it("merges artists from netease and qq and ignores sources without artists", async () => {
|
||||
const app = express();
|
||||
app.use(
|
||||
"/api/music",
|
||||
createMusicRouter(
|
||||
searchProvider("netease", [{ id: "1", name: "N", avatarUrl: "", platform: "netease" }]),
|
||||
searchProvider("qq", [{ id: "2", name: "Q", avatarUrl: "", platform: "qq" }]),
|
||||
fakeProvider("bilibili"),
|
||||
pino({ level: "silent" })
|
||||
)
|
||||
);
|
||||
|
||||
const res = await request(app).get("/api/music/search/all?q=adele");
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.artists).toEqual([
|
||||
{ id: "1", name: "N", avatarUrl: "", platform: "netease" },
|
||||
{ id: "2", name: "Q", avatarUrl: "", platform: "qq" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user