This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1457 from pan93412/refactor/dynamic-to-main
refactor: allow using server statically
- Loading branch information
Showing
4 changed files
with
55 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { cookieToJson } = require('./util') | ||
const request = require('./util/request') | ||
|
||
/** @type {Record<string, any>} */ | ||
let obj = {} | ||
fs.readdirSync(path.join(__dirname, 'module')) | ||
.reverse() | ||
.forEach((file) => { | ||
if (!file.endsWith('.js')) return | ||
let fileModule = require(path.join(__dirname, 'module', file)) | ||
let fn = file.split('.').shift() || '' | ||
obj[fn] = function (data) { | ||
if (typeof data.cookie === 'string') { | ||
data.cookie = cookieToJson(data.cookie) | ||
} | ||
return fileModule( | ||
{ | ||
...data, | ||
cookie: data.cookie ? data.cookie : {}, | ||
}, | ||
request, | ||
) | ||
} | ||
}) | ||
|
||
/** | ||
* @type {Record<string, any> & import("./server")} | ||
*/ | ||
module.exports = { | ||
...require('./server'), | ||
...obj, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const assert = require('assert') | ||
const main = require('./main') | ||
|
||
describe('methods in server.js', () => { | ||
it('has serveNcmApi', () => { | ||
assert.strictEqual(typeof main.serveNcmApi, 'function') | ||
}) | ||
|
||
it('has getModulesDefinitions', () => { | ||
assert.strictEqual(typeof main.getModulesDefinitions, 'function') | ||
}) | ||
}) | ||
|
||
describe('methods in module', () => { | ||
it('has activate_init_profile', () => { | ||
assert.strictEqual(typeof main.activate_init_profile, 'function') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d665429
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
netease-cloud-music-api-binaryify – ./
netease-cloud-music-api-binaryify-git-master-binaryify.vercel.app
netease-cloud-music-api-binaryify.vercel.app
netease-cloud-music-api-binaryify-binaryify.vercel.app
d665429
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
netease-cloud-music-api – ./docs
netease-cloud-music-api-git-master-binaryify.vercel.app
neteasecloudmusicapi.vercel.app