File tree Expand file tree Collapse file tree 1 file changed +30
-9
lines changed Expand file tree Collapse file tree 1 file changed +30
-9
lines changed Original file line number Diff line number Diff line change 1
- import { NeteaseCloudMusicApi } from '@mx-space/extra'
1
+ type Song = {
2
+ author : string
3
+ /**
4
+ * 封面 url
5
+ */
6
+ pic : string
7
+ title : string
2
8
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
6
16
if ( ! id ) {
7
17
return { message : 'id must be not empty stringnumber' }
8
18
}
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 ]
14
35
}
You can’t perform that action at this time.
0 commit comments