You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
826 B
35 lines
826 B
12 months ago
|
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,
|
||
|
}
|