Commit b02d4d5 1 parent 91a3ba7 commit b02d4d5 Copy full SHA for b02d4d5
File tree 4 files changed +55
-24
lines changed
4 files changed +55
-24
lines changed Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' )
2
+ const path = require ( 'path' )
3
+ const { cookieToJson } = require ( './util' )
4
+ const request = require ( './util/request' )
5
+
6
+ /** @type {Record<string, any> } */
7
+ let obj = { }
8
+ fs . readdirSync ( path . join ( __dirname , 'module' ) )
9
+ . reverse ( )
10
+ . forEach ( ( file ) => {
11
+ if ( ! file . endsWith ( '.js' ) ) return
12
+ let fileModule = require ( path . join ( __dirname , 'module' , file ) )
13
+ let fn = file . split ( '.' ) . shift ( ) || ''
14
+ obj [ fn ] = function ( data ) {
15
+ if ( typeof data . cookie === 'string' ) {
16
+ data . cookie = cookieToJson ( data . cookie )
17
+ }
18
+ return fileModule (
19
+ {
20
+ ...data ,
21
+ cookie : data . cookie ? data . cookie : { } ,
22
+ } ,
23
+ request ,
24
+ )
25
+ }
26
+ } )
27
+
28
+ /**
29
+ * @type {Record<string, any> & import("./server") }
30
+ */
31
+ module . exports = {
32
+ ...require ( './server' ) ,
33
+ ...obj ,
34
+ }
Original file line number Diff line number Diff line change
1
+ const assert = require ( 'assert' )
2
+ const main = require ( './main' )
3
+
4
+ describe ( 'methods in server.js' , ( ) => {
5
+ it ( 'has serveNcmApi' , ( ) => {
6
+ assert . strictEqual ( typeof main . serveNcmApi , 'function' )
7
+ } )
8
+
9
+ it ( 'has getModulesDefinitions' , ( ) => {
10
+ assert . strictEqual ( typeof main . getModulesDefinitions , 'function' )
11
+ } )
12
+ } )
13
+
14
+ describe ( 'methods in module' , ( ) => {
15
+ it ( 'has activate_init_profile' , ( ) => {
16
+ assert . strictEqual ( typeof main . activate_init_profile , 'function' )
17
+ } )
18
+ } )
Original file line number Diff line number Diff line change 4
4
"description" : " 网易云音乐 NodeJS 版 API" ,
5
5
"scripts" : {
6
6
"start" : " node app.js" ,
7
- "test" : " mocha -r intelli-espower-loader -t 20000 server.test.js --exit" ,
7
+ "test" : " mocha -r intelli-espower-loader -t 20000 server.test.js main.test.js --exit" ,
8
8
"lint" : " eslint \" **/*.{js,ts}\" " ,
9
9
"lint-fix" : " eslint --fix \" **/*.{js,ts}\" " ,
10
10
"prepare" : " husky install" ,
26
26
" 音乐" ,
27
27
" 网易云音乐nodejs"
28
28
],
29
- "main" : " server .js" ,
29
+ "main" : " main .js" ,
30
30
"types" : " ./interface.d.ts" ,
31
31
"engines" : {
32
32
"node" : " >=12"
78
78
"prettier" : " 2.5.1" ,
79
79
"typescript" : " 4.5.2"
80
80
}
81
- }
81
+ }
Original file line number Diff line number Diff line change @@ -294,28 +294,7 @@ async function serveNcmApi(options) {
294
294
return appExt
295
295
}
296
296
297
- let obj = { }
298
- fs . readdirSync ( path . join ( __dirname , 'module' ) )
299
- . reverse ( )
300
- . forEach ( ( file ) => {
301
- if ( ! file . endsWith ( '.js' ) ) return
302
- let fileModule = require ( path . join ( __dirname , 'module' , file ) )
303
- obj [ file . split ( '.' ) . shift ( ) ] = function ( data ) {
304
- if ( typeof data . cookie === 'string' ) {
305
- data . cookie = cookieToJson ( data . cookie )
306
- }
307
- return fileModule (
308
- {
309
- ...data ,
310
- cookie : data . cookie ? data . cookie : { } ,
311
- } ,
312
- request ,
313
- )
314
- }
315
- } )
316
-
317
297
module . exports = {
318
298
serveNcmApi,
319
299
getModulesDefinitions,
320
- ...obj ,
321
300
}
You can’t perform that action at this time.
0 commit comments