mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 22:51:23 +08:00
refactor: allow using server statically
將原本 "NeteaseCloudMusicApi/server" 掃描 modules 目錄的部分抽出 server.js, 改移到 main.js。這樣使用者就有辦法只載入 靜態的伺服器部分(不動態載入模組)。 這個 patch 的 breaking changes 不易發生。 可作為 patch version 發佈。
This commit is contained in:
@@ -294,28 +294,7 @@ async function serveNcmApi(options) {
|
||||
return appExt
|
||||
}
|
||||
|
||||
let obj = {}
|
||||
fs.readdirSync(path.join(__dirname, 'module'))
|
||||
.reverse()
|
||||
.forEach((file) => {
|
||||
if (!file.endsWith('.js')) return
|
||||
let fileModule = require(path.join(__dirname, 'module', file))
|
||||
obj[file.split('.').shift()] = function (data) {
|
||||
if (typeof data.cookie === 'string') {
|
||||
data.cookie = cookieToJson(data.cookie)
|
||||
}
|
||||
return fileModule(
|
||||
{
|
||||
...data,
|
||||
cookie: data.cookie ? data.cookie : {},
|
||||
},
|
||||
request,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
serveNcmApi,
|
||||
getModulesDefinitions,
|
||||
...obj,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user