Skip to content

Commit 3882aa9

Browse files
committed
fix: update song
Signed-off-by: Innei <[email protected]>
1 parent a2681aa commit 3882aa9

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

kami/functions/song.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1-
import { NeteaseCloudMusicApi } from '@mx-space/extra'
1+
type Song = {
2+
author: string
3+
/**
4+
* 封面 url
5+
*/
6+
pic: string
7+
title: string
28

3-
async function handler() {
4-
const { song_url } = NeteaseCloudMusicApi
5-
const id = context.req.query.id
9+
url: string
10+
}
11+
12+
async function handler(ctx, require) {
13+
const { NeteaseCloudMusicApi } = await require('@mx-space/extra')
14+
const { song_url, song_detail } = NeteaseCloudMusicApi
15+
const id = ctx.req.query.id
616
if (!id) {
717
return { message: 'id must be not empty stringnumber' }
818
}
9-
const data = await song_url({
10-
id: +id,
11-
})
12-
13-
return data.body.data
19+
const [data, data2] = await Promise.all([
20+
song_url({
21+
id: +id,
22+
}),
23+
song_detail({
24+
ids: id,
25+
}),
26+
])
27+
const song = data2.body.songs[0]
28+
const songDetail: Song = {
29+
title: song.name,
30+
author: song.ar?.map((a) => a.name).join(' & '),
31+
pic: song.al?.picUrl,
32+
url: data.body.data?.[0]?.url,
33+
}
34+
return [songDetail]
1435
}

0 commit comments

Comments
 (0)