diff --git a/app.js b/app.js index a2626211528..02fe7c23762 100644 --- a/app.js +++ b/app.js @@ -7,13 +7,15 @@ const packageJSON = require('./package.json') const exec = require('child_process').exec const cache = require('./util/apicache').middleware const { cookieToJson } = require('./util/index') -const fileUpload = require('express-fileupload'); +const fileUpload = require('express-fileupload') // version check exec('npm info NeteaseCloudMusicApi version', (err, stdout, stderr) => { - if(!err){ + if (!err) { let version = stdout.trim() - if(packageJSON.version < version){ - console.log(`最新版本: ${version}, 当前版本: ${packageJSON.version}, 请及时更新`) + if (packageJSON.version < version) { + console.log( + `最新版本: ${version}, 当前版本: ${packageJSON.version}, 请及时更新`, + ) } } }) @@ -22,13 +24,13 @@ const app = express() // CORS & Preflight request app.use((req, res, next) => { - if(req.path !== '/' && !req.path.includes('.')){ + if (req.path !== '/' && !req.path.includes('.')) { res.set({ 'Access-Control-Allow-Credentials': true, 'Access-Control-Allow-Origin': req.headers.origin || '*', 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type', 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS', - 'Content-Type': 'application/json; charset=utf-8' + 'Content-Type': 'application/json; charset=utf-8', }) } req.method === 'OPTIONS' ? res.status(204).end() : next() @@ -36,59 +38,75 @@ app.use((req, res, next) => { // cookie parser app.use((req, res, next) => { - req.cookies = {}, (req.headers.cookie || '').split(/\s*;\s*/).forEach(pair => { - let crack = pair.indexOf('=') - if(crack < 1 || crack == pair.length - 1) return - req.cookies[decodeURIComponent(pair.slice(0, crack)).trim()] = decodeURIComponent(pair.slice(crack + 1)).trim() - }) + req.cookies = {}(req.headers.cookie || '') + .split(/\s*;\s*/) + .forEach((pair) => { + let crack = pair.indexOf('=') + if (crack < 1 || crack == pair.length - 1) return + req.cookies[ + decodeURIComponent(pair.slice(0, crack)).trim() + ] = decodeURIComponent(pair.slice(crack + 1)).trim() + }) next() }) // body parser app.use(bodyParser.json()) -app.use(bodyParser.urlencoded({extended: false})) - -app.use(fileUpload()); - +app.use(bodyParser.urlencoded({ extended: false })) +app.use(fileUpload()) // static app.use(express.static(path.join(__dirname, 'public'))) // cache -app.use(cache('2 minutes', ((req, res) => res.statusCode === 200))) +app.use(cache('2 minutes', (req, res) => res.statusCode === 200)) // router const special = { 'daily_signin.js': '/daily_signin', 'fm_trash.js': '/fm_trash', - 'personal_fm.js': '/personal_fm' + 'personal_fm.js': '/personal_fm', } -fs.readdirSync(path.join(__dirname, 'module')).reverse().forEach(file => { - if(!file.endsWith('.js')) return - let route = (file in special) ? special[file] : '/' + file.replace(/\.js$/i, '').replace(/_/g, '/') - let question = require(path.join(__dirname, 'module', file)) +fs.readdirSync(path.join(__dirname, 'module')) + .reverse() + .forEach((file) => { + if (!file.endsWith('.js')) return + let route = + file in special + ? special[file] + : '/' + file.replace(/\.js$/i, '').replace(/_/g, '/') + let question = require(path.join(__dirname, 'module', file)) - app.use(route, (req, res) => { - if(typeof req.query.cookie === 'string'){ - req.query.cookie = cookieToJson(req.query.cookie) - } - let query = Object.assign({}, {cookie: req.cookies}, req.query, req.body, req.files ) + app.use(route, (req, res) => { + if (typeof req.query.cookie === 'string') { + req.query.cookie = cookieToJson(req.query.cookie) + } + let query = Object.assign( + {}, + { cookie: req.cookies }, + req.query, + req.body, + req.files, + ) - question(query, request) - .then(answer => { - console.log('[OK]', decodeURIComponent(req.originalUrl)) - res.append('Set-Cookie', answer.cookie) - res.status(answer.status).send(answer.body) - }) - .catch(answer => { - console.log('[ERR]', decodeURIComponent(req.originalUrl), {status: answer.status, body: answer.body}) - if(answer.body.code == '301') answer.body.msg = '需要登录' - res.append('Set-Cookie', answer.cookie) - res.status(answer.status).send(answer.body) - }) + question(query, request) + .then((answer) => { + console.log('[OK]', decodeURIComponent(req.originalUrl)) + res.append('Set-Cookie', answer.cookie) + res.status(answer.status).send(answer.body) + }) + .catch((answer) => { + console.log('[ERR]', decodeURIComponent(req.originalUrl), { + status: answer.status, + body: answer.body, + }) + if (answer.body.code == '301') answer.body.msg = '需要登录' + res.append('Set-Cookie', answer.cookie) + res.status(answer.status).send(answer.body) + }) + }) }) -}) const port = process.env.PORT || 3000 const host = process.env.HOST || '' diff --git a/app.test.js b/app.test.js index 69e32baaa5f..2a9e22ab6a8 100644 --- a/app.test.js +++ b/app.test.js @@ -12,7 +12,6 @@ after((done) => { app.server.close(done) }) -fs.readdirSync(path.join(__dirname, 'test')) -.forEach(file => { - require(path.join(__dirname, 'test', file)) -}) \ No newline at end of file +fs.readdirSync(path.join(__dirname, 'test')).forEach((file) => { + require(path.join(__dirname, 'test', file)) +}) diff --git a/docs/sw.js b/docs/sw.js index 1e4aaeb7621..a50f9ba6fc5 100644 --- a/docs/sw.js +++ b/docs/sw.js @@ -11,7 +11,7 @@ const HOSTNAME_WHITELIST = [ self.location.hostname, 'fonts.gstatic.com', 'fonts.googleapis.com', - 'unpkg.com' + 'unpkg.com', ] // The Util Function to hack URLs of intercepted requests @@ -42,7 +42,7 @@ const getFixedUrl = (req) => { * * waitUntil(): activating ====> activated */ -self.addEventListener('activate', event => { +self.addEventListener('activate', (event) => { event.waitUntil(self.clients.claim()) }) @@ -52,7 +52,7 @@ self.addEventListener('activate', event => { * * void respondWith(Promise r) */ -self.addEventListener('fetch', event => { +self.addEventListener('fetch', (event) => { // Skip some of cross-origin requests, like those for Google Analytics. if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) { // Stale-while-revalidate @@ -61,23 +61,30 @@ self.addEventListener('fetch', event => { const cached = caches.match(event.request) const fixedUrl = getFixedUrl(event.request) const fetched = fetch(fixedUrl, { cache: 'no-store' }) - const fetchedCopy = fetched.then(resp => resp.clone()) + const fetchedCopy = fetched.then((resp) => resp.clone()) // Call respondWith() with whatever we get first. // If the fetch fails (e.g disconnected), wait for the cache. // If there’s nothing in cache, wait for the fetch. // If neither yields a response, return offline pages. event.respondWith( - Promise.race([fetched.catch(_ => cached), cached]) - .then(resp => resp || fetched) - .catch(_ => { /* eat any errors */ }) + Promise.race([fetched.catch((_) => cached), cached]) + .then((resp) => resp || fetched) + .catch((_) => { + /* eat any errors */ + }), ) // Update the cache with the version we fetched (only for ok status) event.waitUntil( Promise.all([fetchedCopy, caches.open(RUNTIME)]) - .then(([response, cache]) => response.ok && cache.put(event.request, response)) - .catch(_ => { /* eat any errors */ }) + .then( + ([response, cache]) => + response.ok && cache.put(event.request, response), + ) + .catch((_) => { + /* eat any errors */ + }), ) } }) diff --git a/main.js b/main.js index db2965df1ef..0b214902ce3 100644 --- a/main.js +++ b/main.js @@ -3,20 +3,24 @@ const path = require('path') const request = require('./util/request') const { cookieToJson } = require('./util/index') - 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) +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, + ) } - return fileModule({ - ...data, - cookie: data.cookie ? data.cookie : {} - }, request) - } -}) + }) -module.exports = obj \ No newline at end of file +module.exports = obj diff --git a/module/album.js b/module/album.js index 318e50ee282..bc5e0869365 100644 --- a/module/album.js +++ b/module/album.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/album_detail.js b/module/album_detail.js index d499b13ef1a..a26fef3520f 100644 --- a/module/album_detail.js +++ b/module/album_detail.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/album_detail_dynamic.js b/module/album_detail_dynamic.js index ede2f00a571..3d08e64f739 100644 --- a/module/album_detail_dynamic.js +++ b/module/album_detail_dynamic.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/album_list.js b/module/album_list.js index 3f44174dbe2..fe70dd875c8 100644 --- a/module/album_list.js +++ b/module/album_list.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/album_list_style.js b/module/album_list_style.js index 00340581338..8b92a7a9670 100644 --- a/module/album_list_style.js +++ b/module/album_list_style.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/album_newest.js b/module/album_newest.js index cf94660f8d1..fe1f65063b5 100644 --- a/module/album_newest.js +++ b/module/album_newest.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/album_songsaleboard.js b/module/album_songsaleboard.js index ec8efb47ec7..a7974188233 100644 --- a/module/album_songsaleboard.js +++ b/module/album_songsaleboard.js @@ -19,6 +19,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/artist_album.js b/module/artist_album.js index cafe2ed1727..92a04a78c60 100644 --- a/module/artist_album.js +++ b/module/artist_album.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/artist_desc.js b/module/artist_desc.js index 9237dc4cfc4..c67d7075e78 100644 --- a/module/artist_desc.js +++ b/module/artist_desc.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/artist_sub.js b/module/artist_sub.js index 4e9eebef221..ff46b043fda 100644 --- a/module/artist_sub.js +++ b/module/artist_sub.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/artists.js b/module/artists.js index 2e09262ab4c..3f29e7f4e7b 100644 --- a/module/artists.js +++ b/module/artists.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/avatar_upload.js b/module/avatar_upload.js index 7b2ea18d167..94f018bc9f6 100644 --- a/module/avatar_upload.js +++ b/module/avatar_upload.js @@ -12,7 +12,7 @@ module.exports = async (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) return { status: 200, diff --git a/module/banner.js b/module/banner.js index 4e748f5091f..e2c5b0dbff8 100644 --- a/module/banner.js +++ b/module/banner.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { 'POST', `https://music.163.com/api/v2/banner/get`, { clientType: type }, - { crypto: 'linuxapi', proxy: query.proxy, realIP: query.realIP } + { crypto: 'linuxapi', proxy: query.proxy, realIP: query.realIP }, ) } diff --git a/module/captcha_verify.js b/module/captcha_verify.js index 472b9d21e63..990ce27f260 100644 --- a/module/captcha_verify.js +++ b/module/captcha_verify.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/cellphone_existence_check.js b/module/cellphone_existence_check.js index c79d03eb0e5..feb72644c0b 100644 --- a/module/cellphone_existence_check.js +++ b/module/cellphone_existence_check.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/cellphone/existence/check', realIP: query.realIP, - } + }, ) } diff --git a/module/check_music.js b/module/check_music.js index 1c750b12c97..0e32ef9d8c3 100644 --- a/module/check_music.js +++ b/module/check_music.js @@ -14,7 +14,7 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ).then((response) => { let playable = false if (response.body.code == 200) { diff --git a/module/cloudsearch.js b/module/cloudsearch.js index 82fca370a70..b6e2c26b13d 100644 --- a/module/cloudsearch.js +++ b/module/cloudsearch.js @@ -7,10 +7,15 @@ module.exports = (query, request) => { limit: query.limit || 30, offset: query.offset || 0, } - return request('POST', `https://music.163.com/weapi/cloudsearch/get/web`, data, { - crypto: 'weapi', - cookie: query.cookie, - proxy: query.proxy, - realIP: query.realIP, - }) + return request( + 'POST', + `https://music.163.com/weapi/cloudsearch/get/web`, + data, + { + crypto: 'weapi', + cookie: query.cookie, + proxy: query.proxy, + realIP: query.realIP, + }, + ) } diff --git a/module/comment.js b/module/comment.js index 39cbf874523..e7fd935eaf7 100644 --- a/module/comment.js +++ b/module/comment.js @@ -38,6 +38,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_album.js b/module/comment_album.js index dbc42069b2e..d701d2d25d2 100644 --- a/module/comment_album.js +++ b/module/comment_album.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_dj.js b/module/comment_dj.js index 752588b62a1..70b7dbf278f 100644 --- a/module/comment_dj.js +++ b/module/comment_dj.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_event.js b/module/comment_event.js index 632056de2ce..460a560976e 100644 --- a/module/comment_event.js +++ b/module/comment_event.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_floor.js b/module/comment_floor.js index 5a7bb551c04..53076455a74 100644 --- a/module/comment_floor.js +++ b/module/comment_floor.js @@ -22,6 +22,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_hot.js b/module/comment_hot.js index 5c8c33ad101..b975f3e925c 100644 --- a/module/comment_hot.js +++ b/module/comment_hot.js @@ -25,6 +25,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_hotwall_list.js b/module/comment_hotwall_list.js index f4d4a12dc0b..61d0b16c097 100644 --- a/module/comment_hotwall_list.js +++ b/module/comment_hotwall_list.js @@ -11,6 +11,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_like.js b/module/comment_like.js index 89fc8c13048..2e46287da4e 100644 --- a/module/comment_like.js +++ b/module/comment_like.js @@ -28,6 +28,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_music.js b/module/comment_music.js index ee6f3a9a3c9..9fbc8f1a640 100644 --- a/module/comment_music.js +++ b/module/comment_music.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_mv.js b/module/comment_mv.js index d20681ceed3..979c035caf4 100644 --- a/module/comment_mv.js +++ b/module/comment_mv.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_playlist.js b/module/comment_playlist.js index 7bdc27f6a8e..52fc5449c86 100644 --- a/module/comment_playlist.js +++ b/module/comment_playlist.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/comment_video.js b/module/comment_video.js index d89d4d4a078..ae015a9b811 100644 --- a/module/comment_video.js +++ b/module/comment_video.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/countries_code_list.js b/module/countries_code_list.js index 32d88523763..7d098fabf0f 100644 --- a/module/countries_code_list.js +++ b/module/countries_code_list.js @@ -11,6 +11,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/lbs/countries/v1', realIP: query.realIP, - } + }, ) } diff --git a/module/digitalAlbum_ordering.js b/module/digitalAlbum_ordering.js index 7c930b9a544..471d95be17b 100644 --- a/module/digitalAlbum_ordering.js +++ b/module/digitalAlbum_ordering.js @@ -22,6 +22,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/digitalAlbum_purchased.js b/module/digitalAlbum_purchased.js index 3608f917c20..362dee1b64a 100644 --- a/module/digitalAlbum_purchased.js +++ b/module/digitalAlbum_purchased.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_banner.js b/module/dj_banner.js index 32551feb6ce..6503c3b1440 100644 --- a/module/dj_banner.js +++ b/module/dj_banner.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_category_excludehot.js b/module/dj_category_excludehot.js index b61c43866cb..4a5f1845f62 100644 --- a/module/dj_category_excludehot.js +++ b/module/dj_category_excludehot.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_category_recommend.js b/module/dj_category_recommend.js index a45782fd269..3e96857eaf0 100644 --- a/module/dj_category_recommend.js +++ b/module/dj_category_recommend.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_catelist.js b/module/dj_catelist.js index f4698fe602c..8866be40c10 100644 --- a/module/dj_catelist.js +++ b/module/dj_catelist.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_paygift.js b/module/dj_paygift.js index 96362a38ba4..4424ab99812 100644 --- a/module/dj_paygift.js +++ b/module/dj_paygift.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_program.js b/module/dj_program.js index a95df08f82e..a0fa6469953 100644 --- a/module/dj_program.js +++ b/module/dj_program.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_program_detail.js b/module/dj_program_detail.js index b424937b070..1181951c976 100644 --- a/module/dj_program_detail.js +++ b/module/dj_program_detail.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_program_toplist_hours.js b/module/dj_program_toplist_hours.js index d8bb2d73733..4547636cb1b 100644 --- a/module/dj_program_toplist_hours.js +++ b/module/dj_program_toplist_hours.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_recommend.js b/module/dj_recommend.js index 9266805e92f..e23b056944f 100644 --- a/module/dj_recommend.js +++ b/module/dj_recommend.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_recommend_type.js b/module/dj_recommend_type.js index 0956b23a724..6f3df614f85 100644 --- a/module/dj_recommend_type.js +++ b/module/dj_recommend_type.js @@ -36,6 +36,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_sub.js b/module/dj_sub.js index f604ae40a25..cec5ad7928f 100644 --- a/module/dj_sub.js +++ b/module/dj_sub.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_sublist.js b/module/dj_sublist.js index 91d15e2bc67..6d4bcf2614a 100644 --- a/module/dj_sublist.js +++ b/module/dj_sublist.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_today_perfered.js b/module/dj_today_perfered.js index 78e2e950dd9..8122bad5881 100644 --- a/module/dj_today_perfered.js +++ b/module/dj_today_perfered.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_toplist_newcomer.js b/module/dj_toplist_newcomer.js index e6b75d47b7f..8f28511c93e 100644 --- a/module/dj_toplist_newcomer.js +++ b/module/dj_toplist_newcomer.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/dj_toplist_pay.js b/module/dj_toplist_pay.js index 6fd526c3e4e..5e6caf36c05 100644 --- a/module/dj_toplist_pay.js +++ b/module/dj_toplist_pay.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/fm_trash.js b/module/fm_trash.js index 224d2daad2c..a2019d7d8d8 100644 --- a/module/fm_trash.js +++ b/module/fm_trash.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/follow.js b/module/follow.js index 1e4f3939b2f..d14acf03ce0 100644 --- a/module/follow.js +++ b/module/follow.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/history_recommend_songs.js b/module/history_recommend_songs.js index 67c1b0bd70a..de282c071a5 100644 --- a/module/history_recommend_songs.js +++ b/module/history_recommend_songs.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/history_recommend_songs_detail.js b/module/history_recommend_songs_detail.js index b5d3645a58a..d98c8698d45 100644 --- a/module/history_recommend_songs_detail.js +++ b/module/history_recommend_songs_detail.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/homepage_block_page.js b/module/homepage_block_page.js index 4cfd94673e0..8f6fa1301ca 100644 --- a/module/homepage_block_page.js +++ b/module/homepage_block_page.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/homepage_dragon_ball.js b/module/homepage_dragon_ball.js index e76911a3029..362062a863c 100644 --- a/module/homepage_dragon_ball.js +++ b/module/homepage_dragon_ball.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/homepage/dragon/ball/static', realIP: query.realIP, - } + }, ) } diff --git a/module/like.js b/module/like.js index 1aea4055431..03b60bab6ff 100644 --- a/module/like.js +++ b/module/like.js @@ -18,6 +18,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/login.js b/module/login.js index a201b6ff372..44787ce5a8b 100644 --- a/module/login.js +++ b/module/login.js @@ -21,7 +21,7 @@ module.exports = async (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) if (result.body.code === 502) { return { diff --git a/module/login_cellphone.js b/module/login_cellphone.js index f33f2c1f946..f90189e26e9 100644 --- a/module/login_cellphone.js +++ b/module/login_cellphone.js @@ -22,7 +22,7 @@ module.exports = async (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) if (result.body.code === 200) { diff --git a/module/login_refresh.js b/module/login_refresh.js index 2a6e88ad71f..ac2b6a6c917 100644 --- a/module/login_refresh.js +++ b/module/login_refresh.js @@ -11,6 +11,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/login_status.js b/module/login_status.js index b653a0f9c27..3a38665c285 100644 --- a/module/login_status.js +++ b/module/login_status.js @@ -5,7 +5,7 @@ module.exports = (query, request) => { 'GET', `https://music.163.com`, {}, - { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP } + { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP }, ).then((response) => { try { let profile = eval(`(${/GUser\s*=\s*([^;]+);/.exec(response.body)[1]})`) diff --git a/module/logout.js b/module/logout.js index 4bae68821b2..a92ce4739de 100644 --- a/module/logout.js +++ b/module/logout.js @@ -11,6 +11,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/msg_comments.js b/module/msg_comments.js index f1bef5bd412..76bab8fc7fd 100644 --- a/module/msg_comments.js +++ b/module/msg_comments.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/msg_private_history.js b/module/msg_private_history.js index bfbedde5e2d..0a83b021533 100644 --- a/module/msg_private_history.js +++ b/module/msg_private_history.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/mv_detail_info.js b/module/mv_detail_info.js index 61c4707c3f5..b758a46152a 100644 --- a/module/mv_detail_info.js +++ b/module/mv_detail_info.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/mv_exclusive_rcmd.js b/module/mv_exclusive_rcmd.js index 8ea3043e55d..aee8b2deb8e 100644 --- a/module/mv_exclusive_rcmd.js +++ b/module/mv_exclusive_rcmd.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/mv_first.js b/module/mv_first.js index d22f60ebf58..ae61ad9b7c1 100644 --- a/module/mv_first.js +++ b/module/mv_first.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/mv_sublist.js b/module/mv_sublist.js index d86633b7c3d..2118c41896a 100644 --- a/module/mv_sublist.js +++ b/module/mv_sublist.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/mv_url.js b/module/mv_url.js index 3a0faddee8e..1b8c5181567 100644 --- a/module/mv_url.js +++ b/module/mv_url.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personal_fm.js b/module/personal_fm.js index e2f7a589f81..72ee1fbade9 100644 --- a/module/personal_fm.js +++ b/module/personal_fm.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personalized.js b/module/personalized.js index 45f22bc0242..38a44cad0af 100644 --- a/module/personalized.js +++ b/module/personalized.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personalized_djprogram.js b/module/personalized_djprogram.js index 9b945b4ba94..aa31dd31186 100644 --- a/module/personalized_djprogram.js +++ b/module/personalized_djprogram.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personalized_mv.js b/module/personalized_mv.js index 0af706f1a72..362c9b3a219 100644 --- a/module/personalized_mv.js +++ b/module/personalized_mv.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personalized_newsong.js b/module/personalized_newsong.js index efce8148b79..90f2b8eecd9 100644 --- a/module/personalized_newsong.js +++ b/module/personalized_newsong.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personalized_privatecontent.js b/module/personalized_privatecontent.js index b516d1ab041..56337381d00 100644 --- a/module/personalized_privatecontent.js +++ b/module/personalized_privatecontent.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/personalized_privatecontent_list.js b/module/personalized_privatecontent_list.js index 35fa1868f53..f9ff49eb764 100644 --- a/module/personalized_privatecontent_list.js +++ b/module/personalized_privatecontent_list.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_catlist.js b/module/playlist_catlist.js index 814882eab82..9b148f68dbb 100644 --- a/module/playlist_catlist.js +++ b/module/playlist_catlist.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_cover_update.js b/module/playlist_cover_update.js index ef529ecd258..957b9cc9331 100644 --- a/module/playlist_cover_update.js +++ b/module/playlist_cover_update.js @@ -13,7 +13,7 @@ module.exports = async (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) return { status: 200, diff --git a/module/playlist_desc_update.js b/module/playlist_desc_update.js index 790229afced..ef7b0ca70ff 100644 --- a/module/playlist_desc_update.js +++ b/module/playlist_desc_update.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/playlist/desc/update', realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_detail.js b/module/playlist_detail.js index 4f65b380da9..f4bda3d3965 100644 --- a/module/playlist_detail.js +++ b/module/playlist_detail.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_hot.js b/module/playlist_hot.js index 57cc40e6424..6c085e43ed9 100644 --- a/module/playlist_hot.js +++ b/module/playlist_hot.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_name_update.js b/module/playlist_name_update.js index 5ce73f19514..816168096b6 100644 --- a/module/playlist_name_update.js +++ b/module/playlist_name_update.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/playlist/update/name', realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_order_update.js b/module/playlist_order_update.js index 11c512bead7..268c6eadb12 100644 --- a/module/playlist_order_update.js +++ b/module/playlist_order_update.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_subscribe.js b/module/playlist_subscribe.js index cf9c2aef4c3..e0cce162abc 100644 --- a/module/playlist_subscribe.js +++ b/module/playlist_subscribe.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_subscribers.js b/module/playlist_subscribers.js index 9094f46503c..04260cb9686 100644 --- a/module/playlist_subscribers.js +++ b/module/playlist_subscribers.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_tags_update.js b/module/playlist_tags_update.js index 4b026ed52de..80d82c65c2b 100644 --- a/module/playlist_tags_update.js +++ b/module/playlist_tags_update.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/playlist/tags/update', realIP: query.realIP, - } + }, ) } diff --git a/module/playlist_tracks.js b/module/playlist_tracks.js index fb1cb77a148..2ca3e932a4d 100644 --- a/module/playlist_tracks.js +++ b/module/playlist_tracks.js @@ -20,7 +20,7 @@ module.exports = async (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) return { status: 200, @@ -44,7 +44,7 @@ module.exports = async (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } } diff --git a/module/playmode_intelligence_list.js b/module/playmode_intelligence_list.js index f8cc7a4d05a..b3bc5a314c9 100644 --- a/module/playmode_intelligence_list.js +++ b/module/playmode_intelligence_list.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/program_recommend.js b/module/program_recommend.js index 9302b911798..bd63e7aa945 100644 --- a/module/program_recommend.js +++ b/module/program_recommend.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/rebind.js b/module/rebind.js index c79d7e13c6e..053bcbaad8f 100644 --- a/module/rebind.js +++ b/module/rebind.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/recommend_resource.js b/module/recommend_resource.js index 104775d2eb3..34650871fd6 100644 --- a/module/recommend_resource.js +++ b/module/recommend_resource.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/recommend_songs.js b/module/recommend_songs.js index b88d4576d4c..f83481e5b21 100644 --- a/module/recommend_songs.js +++ b/module/recommend_songs.js @@ -12,6 +12,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/register_cellphone.js b/module/register_cellphone.js index e46af3e3f23..375dd3b8764 100644 --- a/module/register_cellphone.js +++ b/module/register_cellphone.js @@ -18,6 +18,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/related_allvideo.js b/module/related_allvideo.js index 3de13a91c68..e75a8c434f5 100644 --- a/module/related_allvideo.js +++ b/module/related_allvideo.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/related_playlist.js b/module/related_playlist.js index 38ed9cb1c82..6f64b3d48e8 100644 --- a/module/related_playlist.js +++ b/module/related_playlist.js @@ -5,7 +5,12 @@ module.exports = (query, request) => { 'GET', `https://music.163.com/playlist?id=${query.id}`, {}, - { ua: 'pc', cookie: query.cookie, proxy: query.proxy, realIP: query.realIP } + { + ua: 'pc', + cookie: query.cookie, + proxy: query.proxy, + realIP: query.realIP, + }, ).then((response) => { try { const pattern = /
[\s\S]*?[\s\S]*?]*>([^<]+?)<\/a>[\s\S]*?]*>([^<]+?)<\/a>/g diff --git a/module/resource_like.js b/module/resource_like.js index d907136de6d..de285b6c8b4 100644 --- a/module/resource_like.js +++ b/module/resource_like.js @@ -24,6 +24,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/search_default.js b/module/search_default.js index 0d40840c979..1e14ee53110 100644 --- a/module/search_default.js +++ b/module/search_default.js @@ -11,6 +11,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/search/defaultkeyword/get', realIP: query.realIP, - } + }, ) } diff --git a/module/search_hot_detail.js b/module/search_hot_detail.js index 902ba0b27bd..aae7c7e1726 100644 --- a/module/search_hot_detail.js +++ b/module/search_hot_detail.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/search_multimatch.js b/module/search_multimatch.js index 13dbfa3b202..6e4c0e8f86d 100644 --- a/module/search_multimatch.js +++ b/module/search_multimatch.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/search_suggest.js b/module/search_suggest.js index 68098b3299d..e78b255d98c 100644 --- a/module/search_suggest.js +++ b/module/search_suggest.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/share_resource.js b/module/share_resource.js index a2aa81441bb..a9f413fbd0b 100644 --- a/module/share_resource.js +++ b/module/share_resource.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/simi_artist.js b/module/simi_artist.js index 8d1ccac66cf..555c1d9abe6 100644 --- a/module/simi_artist.js +++ b/module/simi_artist.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/simi_playlist.js b/module/simi_playlist.js index 2f4f622b27d..11052df3062 100644 --- a/module/simi_playlist.js +++ b/module/simi_playlist.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/simi_song.js b/module/simi_song.js index cbc6d772acd..58b3be9e289 100644 --- a/module/simi_song.js +++ b/module/simi_song.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/simi_user.js b/module/simi_user.js index 82c5d65a0b0..65a96d19b63 100644 --- a/module/simi_user.js +++ b/module/simi_user.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/song_order_update.js b/module/song_order_update.js index 33369b69692..0dfb416c74d 100644 --- a/module/song_order_update.js +++ b/module/song_order_update.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/playlist/desc/update', realIP: query.realIP, - } + }, ) } diff --git a/module/song_url.js b/module/song_url.js index f8125ff944b..7612733ba4e 100644 --- a/module/song_url.js +++ b/module/song_url.js @@ -19,6 +19,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/top_album.js b/module/top_album.js index 960e7d38516..e1e93188cb5 100644 --- a/module/top_album.js +++ b/module/top_album.js @@ -11,7 +11,7 @@ module.exports = (query, request) => { year: query.year || date.getFullYear(), month: query.month || date.getMonth() + 1, total: false, - rcmd: false + rcmd: false, } return request( 'POST', @@ -22,6 +22,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/top_list.js b/module/top_list.js index 324d318739a..c33b251abb6 100644 --- a/module/top_list.js +++ b/module/top_list.js @@ -25,6 +25,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/top_playlist_highquality.js b/module/top_playlist_highquality.js index 669a0ce3462..76ac9f94719 100644 --- a/module/top_playlist_highquality.js +++ b/module/top_playlist_highquality.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/top_song.js b/module/top_song.js index f9d4d794a67..4b37d38d480 100644 --- a/module/top_song.js +++ b/module/top_song.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/toplist.js b/module/toplist.js index e57bd41e089..592b636ac96 100644 --- a/module/toplist.js +++ b/module/toplist.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/toplist_detail.js b/module/toplist_detail.js index eca0e9d322f..e194e03c5d4 100644 --- a/module/toplist_detail.js +++ b/module/toplist_detail.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_audio.js b/module/user_audio.js index 2e2a07097d5..b63e7009d47 100644 --- a/module/user_audio.js +++ b/module/user_audio.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_cloud_detail.js b/module/user_cloud_detail.js index 5a2a43c7d32..45f1b5a1c27 100644 --- a/module/user_cloud_detail.js +++ b/module/user_cloud_detail.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_detail.js b/module/user_detail.js index 8822347703c..b3da3404cbc 100644 --- a/module/user_detail.js +++ b/module/user_detail.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_dj.js b/module/user_dj.js index 87dd5fdba20..45a6a3aec8b 100644 --- a/module/user_dj.js +++ b/module/user_dj.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_event.js b/module/user_event.js index 75252cf69d0..c64e0cac51f 100644 --- a/module/user_event.js +++ b/module/user_event.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_followeds.js b/module/user_followeds.js index 078e30b75f6..a071ed27b38 100644 --- a/module/user_followeds.js +++ b/module/user_followeds.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { proxy: query.proxy, url: '/api/user/getfolloweds', realIP: query.realIP, - } + }, ) } diff --git a/module/user_follows.js b/module/user_follows.js index a6e085bac32..cff742f410e 100644 --- a/module/user_follows.js +++ b/module/user_follows.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_subcount.js b/module/user_subcount.js index bebe81c242a..cfa53ab8f5c 100644 --- a/module/user_subcount.js +++ b/module/user_subcount.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/user_update.js b/module/user_update.js index cbb1f4f52ea..96c7af1b9c6 100644 --- a/module/user_update.js +++ b/module/user_update.js @@ -19,6 +19,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_category_list.js b/module/video_category_list.js index 530e1d6e19f..88c13c74e37 100644 --- a/module/video_category_list.js +++ b/module/video_category_list.js @@ -15,6 +15,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_detail.js b/module/video_detail.js index 9e748f66e9b..63507ae9199 100644 --- a/module/video_detail.js +++ b/module/video_detail.js @@ -13,6 +13,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_detail_info.js b/module/video_detail_info.js index f5de495cd1d..4a163ae9d43 100644 --- a/module/video_detail_info.js +++ b/module/video_detail_info.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_group.js b/module/video_group.js index ef8f20e7526..9c391299d4a 100644 --- a/module/video_group.js +++ b/module/video_group.js @@ -16,6 +16,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_group_list.js b/module/video_group_list.js index 6d6630f0486..22acdc7f0b9 100644 --- a/module/video_group_list.js +++ b/module/video_group_list.js @@ -11,6 +11,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_sub.js b/module/video_sub.js index eaeb5a73289..562a7c22076 100644 --- a/module/video_sub.js +++ b/module/video_sub.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_timeline_all.js b/module/video_timeline_all.js index 2070cfa085d..b05a46c3d36 100644 --- a/module/video_timeline_all.js +++ b/module/video_timeline_all.js @@ -17,6 +17,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/video_url.js b/module/video_url.js index 79c2767318e..b564f8a2497 100644 --- a/module/video_url.js +++ b/module/video_url.js @@ -14,6 +14,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module/weblog.js b/module/weblog.js index d012e839e4c..1b593e341fe 100644 --- a/module/weblog.js +++ b/module/weblog.js @@ -10,6 +10,6 @@ module.exports = (query, request) => { cookie: query.cookie, proxy: query.proxy, realIP: query.realIP, - } + }, ) } diff --git a/module_example/avatar_upload.js b/module_example/avatar_upload.js index 5874714f172..39ea5e51234 100644 --- a/module_example/avatar_upload.js +++ b/module_example/avatar_upload.js @@ -5,16 +5,16 @@ const path = require('path') async function main() { const result = await login_cellphone({ phone: '手机号', - password: '密码' + password: '密码', }) const filePath = './test.jpg' await avatar_upload({ imgFile: { name: path.basename(filePath), - data: fs.readFileSync(filePath) + data: fs.readFileSync(filePath), }, imgSize: 1012, //图片尺寸,需要正方形图片 - cookie: result.body.cookie + cookie: result.body.cookie, }) } -main() \ No newline at end of file +main() diff --git a/module_example/test.js b/module_example/test.js index 93a4db5f218..1a019d73b89 100644 --- a/module_example/test.js +++ b/module_example/test.js @@ -1,27 +1,31 @@ -const { login_cellphone, user_cloud, album_sublist, song_url } = require('../main') +const { + login_cellphone, + user_cloud, + album_sublist, + song_url, +} = require('../main') async function test() { try { const result = await login_cellphone({ phone: '手机号', - password: '密码' + password: '密码', }) console.log(result) const result2 = await user_cloud({ - cookie: result.body.cookie + cookie: result.body.cookie, }) console.log(result2.body) const result3 = await album_sublist({ - cookie: result.body.cookie + cookie: result.body.cookie, }) console.log(result3.body) const result4 = await song_url({ cookie: result.body.cookie, - id: 33894312 + id: 33894312, }) console.log(result4.body) - } catch (error) { console.log(error) } } -test() \ No newline at end of file +test() diff --git a/plugins/upload.js b/plugins/upload.js index 8aacc6074a2..cddb52bdd70 100644 --- a/plugins/upload.js +++ b/plugins/upload.js @@ -14,7 +14,7 @@ module.exports = async (query, request) => { 'POST', `https://music.163.com/weapi/nos/token/alloc`, data, - { crypto: 'weapi', cookie: query.cookie, proxy: query.proxy } + { crypto: 'weapi', cookie: query.cookie, proxy: query.proxy }, ) // 上传图片 const res2 = await axios({ @@ -34,15 +34,15 @@ module.exports = async (query, request) => { 'POST', `https://music.163.com/upload/img/op?id=${res.body.result.docId}&op=${imgX}y${imgY}y${imgSize}y${imgSize}`, {}, - { crypto: 'weapi', cookie: query.cookie, proxy: query.proxy } + { crypto: 'weapi', cookie: query.cookie, proxy: query.proxy }, ) - - return { + + return { // ...res.body.result, // ...res2.data, // ...res3.body, url_pre: 'https://p1.music.126.net/' + res.body.result.objectKey, url: res3.body.url, - imgId: res3.body.id + imgId: res3.body.id, } } diff --git a/test/album.test.js b/test/album.test.js index 33270c1500b..4709d8546ee 100644 --- a/test/album.test.js +++ b/test/album.test.js @@ -3,18 +3,17 @@ const request = require('request') const host = global.host || 'http://localhost:3000' describe('测试获取歌手专辑列表是否正常', () => { - it('数据的 code 应该为200', done => { + it('数据的 code 应该为200', (done) => { const qs = { - id: 32311 + id: 32311, } - request.get({url: `${host}/album`, qs: qs}, (err, res, body) => { + request.get({ url: `${host}/album`, qs: qs }, (err, res, body) => { if (!err && res.statusCode == 200) { body = JSON.parse(body) assert(body.code === 200) done() - } - else{ + } else { done(err) } }) diff --git a/test/comment.test.js b/test/comment.test.js index 595eb1b3d75..1637068c7ea 100644 --- a/test/comment.test.js +++ b/test/comment.test.js @@ -3,18 +3,17 @@ const request = require('request') const host = global.host || 'http://localhost:3000' describe('测试获取评论是否正常', () => { - it('数据的 code 应该为200', done => { + it('数据的 code 应该为200', (done) => { const qs = { - id: 32311 + id: 32311, } - request.get({url: `${host}/comment/album`, qs: qs}, (err, res, body) => { + request.get({ url: `${host}/comment/album`, qs: qs }, (err, res, body) => { if (!err && res.statusCode == 200) { body = JSON.parse(body) assert(body.code === 200) done() - } - else{ + } else { done(err) } }) diff --git a/test/login.test.js b/test/login.test.js index a9e5a42e53c..cff3f8e0380 100644 --- a/test/login.test.js +++ b/test/login.test.js @@ -2,25 +2,27 @@ const assert = require('assert') const request = require('request') const host = global.host || 'http://localhost:3000' -console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!'); +console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!') const phone = '' const password = '' describe('测试登录是否正常', () => { - it('手机登录 code 应该等于200', done => { + it('手机登录 code 应该等于200', (done) => { const qs = { - phone: process.env.NCM_API_TEST_LOGIN_PHONE || phone || '', - password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '' + phone: process.env.NCM_API_TEST_LOGIN_PHONE || phone || '', + password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '', } - request.get({url: `${host}/login/cellphone`, qs: qs}, (err, res, body) => { - if (!err && res.statusCode == 200) { - body = JSON.parse(body) - assert(body.code === 200) - done() - } - else{ - done(err) - } - }) + request.get( + { url: `${host}/login/cellphone`, qs: qs }, + (err, res, body) => { + if (!err && res.statusCode == 200) { + body = JSON.parse(body) + assert(body.code === 200) + done() + } else { + done(err) + } + }, + ) }) }) diff --git a/test/lyric.test.js b/test/lyric.test.js index 19174ffb77b..7d3451bffcf 100644 --- a/test/lyric.test.js +++ b/test/lyric.test.js @@ -3,18 +3,17 @@ const request = require('request') const host = global.host || 'http://localhost:3000' describe('测试获取歌词是否正常', () => { - it('数据应该有 lrc 字段', done => { + it('数据应该有 lrc 字段', (done) => { const qs = { - id: 347230 + id: 347230, } - request.get({url: `${host}/lyric`, qs: qs}, (err, res, body) => { + request.get({ url: `${host}/lyric`, qs: qs }, (err, res, body) => { if (!err && res.statusCode == 200) { body = JSON.parse(body) assert(typeof body.lrc !== 'undefined') done() - } - else{ + } else { done(err) } }) diff --git a/test/music_url.test.js b/test/music_url.test.js index dc57271df37..8661ac8440a 100644 --- a/test/music_url.test.js +++ b/test/music_url.test.js @@ -3,21 +3,20 @@ const request = require('request') const host = global.host || 'http://localhost:3000' describe('测试获取歌曲是否正常', () => { - it('歌曲的 url 不应该为空', done => { + it('歌曲的 url 不应该为空', (done) => { const qs = { id: 462791935, - br: 999000 + br: 999000, } - request.get({url: `${host}/song/url`, qs: qs}, (err, res, body) => { + request.get({ url: `${host}/song/url`, qs: qs }, (err, res, body) => { if (!err && res.statusCode == 200) { body = JSON.parse(body) assert(!!body.data[0].url) done() - } - else{ + } else { done(err) } }) - }); -}); + }) +}) diff --git a/test/search.test.js b/test/search.test.js index 49b93a82ac6..89c62e160a2 100644 --- a/test/search.test.js +++ b/test/search.test.js @@ -3,18 +3,17 @@ const request = require('request') const host = global.host || 'http://localhost:3000' describe('测试搜索是否正常', () => { - it('获取到的数据的 name 应该和搜索关键词一致', done => { + it('获取到的数据的 name 应该和搜索关键词一致', (done) => { const qs = { keywords: '海阔天空', - type: 1 + type: 1, } - request.get({url: `${host}/search`, qs: qs}, (err, res, body) => { + request.get({ url: `${host}/search`, qs: qs }, (err, res, body) => { if (!err && res.statusCode == 200) { body = JSON.parse(body) assert(body.result.songs[0].name === '海阔天空') done() - } - else{ + } else { done(err) } }) diff --git a/util/apicache.js b/util/apicache.js index a39c0218b28..a71c9987310 100644 --- a/util/apicache.js +++ b/util/apicache.js @@ -13,19 +13,19 @@ var t = { var instances = [] -var matches = function(a) { - return function(b) { +var matches = function (a) { + return function (b) { return a === b } } -var doesntMatch = function(a) { - return function(b) { +var doesntMatch = function (a) { + return function (b) { return !matches(a)(b) } } -var logDuration = function(d, prefix) { +var logDuration = function (d, prefix) { var str = d > 1000 ? (d / 1000).toFixed(2) + 'sec' : d + 'ms' return '\x1b[33m- ' + (prefix ? prefix + ' ' : '') + str + '\x1b[0m' } @@ -68,10 +68,12 @@ function ApiCache() { this.id = instances.length function debug(a, b, c, d) { - var arr = ['\x1b[36m[apicache]\x1b[0m', a, b, c, d].filter(function(arg) { + var arr = ['\x1b[36m[apicache]\x1b[0m', a, b, c, d].filter(function (arg) { return arg !== undefined }) - var debugEnv = process.env.DEBUG && process.env.DEBUG.split(',').indexOf('apicache') !== -1 + var debugEnv = + process.env.DEBUG && + process.env.DEBUG.split(',').indexOf('apicache') !== -1 return (globalOptions.debug || debugEnv) && console.log.apply(null, arr) } @@ -86,9 +88,17 @@ function ApiCache() { return false } - if (codes.exclude && codes.exclude.length && codes.exclude.indexOf(response.statusCode) !== -1) + if ( + codes.exclude && + codes.exclude.length && + codes.exclude.indexOf(response.statusCode) !== -1 + ) return false - if (codes.include && codes.include.length && codes.include.indexOf(response.statusCode) === -1) + if ( + codes.include && + codes.include.length && + codes.include.indexOf(response.statusCode) === -1 + ) return false return true @@ -108,10 +118,10 @@ function ApiCache() { function filterBlacklistedHeaders(headers) { return Object.keys(headers) - .filter(function(key) { + .filter(function (key) { return globalOptions.headerBlacklist.indexOf(key) === -1 }) - .reduce(function(acc, header) { + .reduce(function (acc, header) { acc[header] = headers[header] return acc }, {}) @@ -135,7 +145,7 @@ function ApiCache() { try { redis.hset(key, 'response', JSON.stringify(value)) redis.hset(key, 'duration', duration) - redis.expire(key, duration / 1000, expireCallback || function() {}) + redis.expire(key, duration / 1000, expireCallback || function () {}) } catch (err) { debug('[apicache] error in redis.hset()') } @@ -144,7 +154,7 @@ function ApiCache() { } // add automatic cache clearing from duration, includes max limit on setTimeout - timers[key] = setTimeout(function() { + timers[key] = setTimeout(function () { instance.clear(key, true) }, Math.min(duration, 2147483647)) } @@ -157,7 +167,9 @@ function ApiCache() { var oldContent = res._apicache.content if (typeof oldContent === 'string') { - oldContent = !Buffer.from ? new Buffer(oldContent) : Buffer.from(oldContent) + oldContent = !Buffer.from + ? new Buffer(oldContent) + : Buffer.from(oldContent) } if (!oldContent) { @@ -166,7 +178,7 @@ function ApiCache() { res._apicache.content = Buffer.concat( [oldContent, content], - oldContent.length + content.length + oldContent.length + content.length, ) } else { res._apicache.content = content @@ -174,7 +186,15 @@ function ApiCache() { } } - function makeResponseCacheable(req, res, next, key, duration, strDuration, toggle) { + function makeResponseCacheable( + req, + res, + next, + key, + duration, + strDuration, + toggle, + ) { // monkeypatch res.end to create cache object res._apicache = { write: res.write, @@ -185,15 +205,18 @@ function ApiCache() { } // append header overwrites if applicable - Object.keys(globalOptions.headers).forEach(function(name) { + Object.keys(globalOptions.headers).forEach(function (name) { res.setHeader(name, globalOptions.headers[name]) }) - res.writeHead = function() { + res.writeHead = function () { // add cache control headers if (!globalOptions.headers['cache-control']) { if (shouldCacheResponse(req, res, toggle)) { - res.setHeader('cache-control', 'max-age=' + (duration / 1000).toFixed(0)) + res.setHeader( + 'cache-control', + 'max-age=' + (duration / 1000).toFixed(0), + ) } else { res.setHeader('cache-control', 'no-cache, no-store, must-revalidate') } @@ -204,13 +227,13 @@ function ApiCache() { } // patch res.write - res.write = function(content) { + res.write = function (content) { accumulateContent(res, content) return res._apicache.write.apply(this, arguments) } // patch res.end - res.end = function(content, encoding) { + res.end = function (content, encoding) { if (shouldCacheResponse(req, res, toggle)) { accumulateContent(res, content) @@ -221,13 +244,16 @@ function ApiCache() { res.statusCode, headers, res._apicache.content, - encoding + encoding, ) cacheResponse(key, cacheObject, duration) // display log entry var elapsed = new Date() - req.apicacheTimer - debug('adding cache entry for "' + key + '" @ ' + strDuration, logDuration(elapsed)) + debug( + 'adding cache entry for "' + key + '" @ ' + strDuration, + logDuration(elapsed), + ) debug('_apicache.headers: ', res._apicache.headers) debug('res.getHeaders(): ', getSafeHeaders(res)) debug('cacheObject: ', cacheObject) @@ -240,31 +266,46 @@ function ApiCache() { next() } - function sendCachedResponse(request, response, cacheObject, toggle, next, duration) { + function sendCachedResponse( + request, + response, + cacheObject, + toggle, + next, + duration, + ) { if (toggle && !toggle(request, response)) { return next() } var headers = getSafeHeaders(response) - Object.assign(headers, filterBlacklistedHeaders(cacheObject.headers || {}), { - // set properly-decremented max-age header. This ensures that max-age is in sync with the cache expiration. - 'cache-control': - 'max-age=' + - Math.max( - 0, - (duration / 1000 - (new Date().getTime() / 1000 - cacheObject.timestamp)).toFixed(0) - ), - }) + Object.assign( + headers, + filterBlacklistedHeaders(cacheObject.headers || {}), + { + // set properly-decremented max-age header. This ensures that max-age is in sync with the cache expiration. + 'cache-control': + 'max-age=' + + Math.max( + 0, + ( + duration / 1000 - + (new Date().getTime() / 1000 - cacheObject.timestamp) + ).toFixed(0), + ), + }, + ) // only embed apicache headers when not in production environment - // unstringify buffers var data = cacheObject.data if (data && data.type === 'Buffer') { data = - typeof data.data === 'number' ? new Buffer.alloc(data.data) : new Buffer.from(data.data) + typeof data.data === 'number' + ? new Buffer.alloc(data.data) + : new Buffer.from(data.data) } // test Etag against If-None-Match for 304 @@ -283,18 +324,22 @@ function ApiCache() { function syncOptions() { for (var i in middlewareOptions) { - Object.assign(middlewareOptions[i].options, globalOptions, middlewareOptions[i].localOptions) + Object.assign( + middlewareOptions[i].options, + globalOptions, + middlewareOptions[i].localOptions, + ) } } - this.clear = function(target, isAutomatic) { + this.clear = function (target, isAutomatic) { var group = index.groups[target] var redis = globalOptions.redisClient if (group) { debug('clearing group "' + target + '"') - group.forEach(function(key) { + group.forEach(function (key) { debug('clearing cached entry for "' + key + '"') clearTimeout(timers[key]) delete timers[key] @@ -312,7 +357,13 @@ function ApiCache() { delete index.groups[target] } else if (target) { - debug('clearing ' + (isAutomatic ? 'expired' : 'cached') + ' entry for "' + target + '"') + debug( + 'clearing ' + + (isAutomatic ? 'expired' : 'cached') + + ' entry for "' + + target + + '"', + ) clearTimeout(timers[target]) delete timers[target] // clear actual cached entry @@ -330,8 +381,10 @@ function ApiCache() { index.all = index.all.filter(doesntMatch(target)) // remove target from each group that it may exist in - Object.keys(index.groups).forEach(function(groupName) { - index.groups[groupName] = index.groups[groupName].filter(doesntMatch(target)) + Object.keys(index.groups).forEach(function (groupName) { + index.groups[groupName] = index.groups[groupName].filter( + doesntMatch(target), + ) // delete group if now empty if (!index.groups[groupName].length) { @@ -345,7 +398,7 @@ function ApiCache() { memCache.clear() } else { // clear redis keys one by one from internal index to prevent clearing non-apicache entries - index.all.forEach(function(key) { + index.all.forEach(function (key) { clearTimeout(timers[key]) delete timers[key] try { @@ -381,7 +434,7 @@ function ApiCache() { return defaultDuration } - this.getDuration = function(duration) { + this.getDuration = function (duration) { return parseDuration(duration, globalOptions.defaultDuration) } @@ -393,13 +446,13 @@ function ApiCache() { * }) * */ - this.getPerformance = function() { - return performanceArray.map(function(p) { + this.getPerformance = function () { + return performanceArray.map(function (p) { return p.report() }) } - this.getIndex = function(group) { + this.getIndex = function (group) { if (group) { return index.groups[group] } else { @@ -407,7 +460,11 @@ function ApiCache() { } } - this.middleware = function cache(strDuration, middlewareToggle, localOptions) { + this.middleware = function cache( + strDuration, + middlewareToggle, + localOptions, + ) { var duration = instance.getDuration(strDuration) var opt = {} @@ -415,9 +472,9 @@ function ApiCache() { options: opt, }) - var options = function(localOptions) { + var options = function (localOptions) { if (localOptions) { - middlewareOptions.find(function(middleware) { + middlewareOptions.find(function (middleware) { return middleware.options === opt }).localOptions = localOptions } @@ -433,7 +490,7 @@ function ApiCache() { * A Function for non tracking performance */ function NOOPCachePerformance() { - this.report = this.hit = this.miss = function() {} // noop; + this.report = this.hit = this.miss = function () {} // noop; } /** @@ -487,7 +544,7 @@ function ApiCache() { /** * Return performance statistics */ - this.report = function() { + this.report = function () { return { lastCacheHit: this.lastCacheHit, lastCacheMiss: this.lastCacheMiss, @@ -507,7 +564,7 @@ function ApiCache() { * @param {Uint8Array} array An array representing hits and misses. * @returns a number between 0 and 1, or null if the array has no hits or misses */ - this.hitRate = function(array) { + this.hitRate = function (array) { var hits = 0 var misses = 0 for (var i = 0; i < array.length; i++) { @@ -540,7 +597,7 @@ function ApiCache() { * 01 encodes a hit * 10 encodes a miss */ - this.recordHitInArray = function(array, hit) { + this.recordHitInArray = function (array, hit) { var arrayIndex = ~~(this.callCount / 4) % array.length var bitOffset = (this.callCount % 4) * 2 // 2 bits per record, 4 records per uint8 array element var clearMask = ~(3 << bitOffset) @@ -552,7 +609,7 @@ function ApiCache() { * Records the hit or miss in the tracking arrays and increments the call count. * @param {boolean} hit true records a hit, false records a miss */ - this.recordHit = function(hit) { + this.recordHit = function (hit) { this.recordHitInArray(this.hitsLast100, hit) this.recordHitInArray(this.hitsLast1000, hit) this.recordHitInArray(this.hitsLast10000, hit) @@ -565,7 +622,7 @@ function ApiCache() { * Records a hit event, setting lastCacheMiss to the given key * @param {string} key The key that had the cache hit */ - this.hit = function(key) { + this.hit = function (key) { this.recordHit(true) this.lastCacheHit = key } @@ -574,17 +631,19 @@ function ApiCache() { * Records a miss event, setting lastCacheMiss to the given key * @param {string} key The key that had the cache miss */ - this.miss = function(key) { + this.miss = function (key) { this.recordHit(false) this.lastCacheMiss = key } } - var perf = globalOptions.trackPerformance ? new CachePerformance() : new NOOPCachePerformance() + var perf = globalOptions.trackPerformance + ? new CachePerformance() + : new NOOPCachePerformance() performanceArray.push(perf) - var cache = function(req, res, next) { + var cache = function (req, res, next) { function bypass() { debug('bypass detected, skipping cache.') return next() @@ -592,7 +651,11 @@ function ApiCache() { // initial bypass chances if (!opt.enabled) return bypass() - if (req.headers['x-apicache-bypass'] || req.headers['x-apicache-force-fetch']) return bypass() + if ( + req.headers['x-apicache-bypass'] || + req.headers['x-apicache-force-fetch'] + ) + return bypass() // REMOVED IN 0.11.1 TO CORRECT MIDDLEWARE TOGGLE EXECUTE ORDER // if (typeof middlewareToggle === 'function') { @@ -631,19 +694,34 @@ function ApiCache() { // send if cache hit from memory-cache if (cached) { var elapsed = new Date() - req.apicacheTimer - debug('sending cached (memory-cache) version of', key, logDuration(elapsed)) + debug( + 'sending cached (memory-cache) version of', + key, + logDuration(elapsed), + ) perf.hit(key) - return sendCachedResponse(req, res, cached, middlewareToggle, next, duration) + return sendCachedResponse( + req, + res, + cached, + middlewareToggle, + next, + duration, + ) } // send if cache hit from redis if (redis && redis.connected) { try { - redis.hgetall(key, function(err, obj) { + redis.hgetall(key, function (err, obj) { if (!err && obj && obj.response) { var elapsed = new Date() - req.apicacheTimer - debug('sending cached (redis) version of', key, logDuration(elapsed)) + debug( + 'sending cached (redis) version of', + key, + logDuration(elapsed), + ) perf.hit(key) return sendCachedResponse( @@ -652,7 +730,7 @@ function ApiCache() { JSON.parse(obj.response), middlewareToggle, next, - duration + duration, ) } else { perf.miss(key) @@ -663,18 +741,34 @@ function ApiCache() { key, duration, strDuration, - middlewareToggle + middlewareToggle, ) } }) } catch (err) { // bypass redis on error perf.miss(key) - return makeResponseCacheable(req, res, next, key, duration, strDuration, middlewareToggle) + return makeResponseCacheable( + req, + res, + next, + key, + duration, + strDuration, + middlewareToggle, + ) } } else { perf.miss(key) - return makeResponseCacheable(req, res, next, key, duration, strDuration, middlewareToggle) + return makeResponseCacheable( + req, + res, + next, + key, + duration, + strDuration, + middlewareToggle, + ) } } @@ -683,18 +777,23 @@ function ApiCache() { return cache } - this.options = function(options) { + this.options = function (options) { if (options) { Object.assign(globalOptions, options) syncOptions() if ('defaultDuration' in options) { // Convert the default duration to a number in milliseconds (if needed) - globalOptions.defaultDuration = parseDuration(globalOptions.defaultDuration, 3600000) + globalOptions.defaultDuration = parseDuration( + globalOptions.defaultDuration, + 3600000, + ) } if (globalOptions.trackPerformance) { - debug('WARNING: using trackPerformance flag can cause high memory usage!') + debug( + 'WARNING: using trackPerformance flag can cause high memory usage!', + ) } return this @@ -703,14 +802,14 @@ function ApiCache() { } } - this.resetIndex = function() { + this.resetIndex = function () { index = { all: [], groups: {}, } } - this.newInstance = function(config) { + this.newInstance = function (config) { var instance = new ApiCache() if (config) { @@ -720,7 +819,7 @@ function ApiCache() { return instance } - this.clone = function() { + this.clone = function () { return this.newInstance(this.options()) } @@ -728,4 +827,4 @@ function ApiCache() { this.resetIndex() } -module.exports = new ApiCache() \ No newline at end of file +module.exports = new ApiCache() diff --git a/util/crypto.js b/util/crypto.js index b3a6392700d..3f99e858e32 100644 --- a/util/crypto.js +++ b/util/crypto.js @@ -3,7 +3,8 @@ const iv = Buffer.from('0102030405060708') const presetKey = Buffer.from('0CoJUm6Qyw8W8jud') const linuxapiKey = Buffer.from('rFgB&h#%2?^eDg:Q') const base62 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' -const publicKey = '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgtQn2JZ34ZC28NWYpAUd98iZ37BUrX/aKzmFbt7clFSs6sXqHauqKWqdtLkF2KexO40H1YTX8z2lSgBBOAxLsvaklV8k4cBFK9snQXE9/DDaFt6Rr7iVZMldczhC0JNgTz+SHXT6CBHuX3e9SdB1Ua44oncaTWz7OBGLbCiK45wIDAQAB\n-----END PUBLIC KEY-----' +const publicKey = + '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgtQn2JZ34ZC28NWYpAUd98iZ37BUrX/aKzmFbt7clFSs6sXqHauqKWqdtLkF2KexO40H1YTX8z2lSgBBOAxLsvaklV8k4cBFK9snQXE9/DDaFt6Rr7iVZMldczhC0JNgTz+SHXT6CBHuX3e9SdB1Ua44oncaTWz7OBGLbCiK45wIDAQAB\n-----END PUBLIC KEY-----' const eapiKey = 'e82ckenh8dichen8' const aesEncrypt = (buffer, mode, key, iv) => { @@ -13,38 +14,54 @@ const aesEncrypt = (buffer, mode, key, iv) => { const rsaEncrypt = (buffer, key) => { buffer = Buffer.concat([Buffer.alloc(128 - buffer.length), buffer]) - return crypto.publicEncrypt({key: key, padding: crypto.constants.RSA_NO_PADDING}, buffer) + return crypto.publicEncrypt( + { key: key, padding: crypto.constants.RSA_NO_PADDING }, + buffer, + ) } const weapi = (object) => { const text = JSON.stringify(object) - const secretKey = crypto.randomBytes(16).map(n => (base62.charAt(n % 62).charCodeAt())) + const secretKey = crypto + .randomBytes(16) + .map((n) => base62.charAt(n % 62).charCodeAt()) return { - params: aesEncrypt(Buffer.from(aesEncrypt(Buffer.from(text), 'cbc', presetKey, iv).toString('base64')), 'cbc', secretKey, iv).toString('base64'), - encSecKey: rsaEncrypt(secretKey.reverse(), publicKey).toString('hex') + params: aesEncrypt( + Buffer.from( + aesEncrypt(Buffer.from(text), 'cbc', presetKey, iv).toString('base64'), + ), + 'cbc', + secretKey, + iv, + ).toString('base64'), + encSecKey: rsaEncrypt(secretKey.reverse(), publicKey).toString('hex'), } } const linuxapi = (object) => { const text = JSON.stringify(object) return { - eparams: aesEncrypt(Buffer.from(text), 'ecb', linuxapiKey, '').toString('hex').toUpperCase() + eparams: aesEncrypt(Buffer.from(text), 'ecb', linuxapiKey, '') + .toString('hex') + .toUpperCase(), } } const eapi = (url, object) => { - const text = typeof object === 'object' ? JSON.stringify(object) : object; + const text = typeof object === 'object' ? JSON.stringify(object) : object const message = `nobody${url}use${text}md5forencrypt` const digest = crypto.createHash('md5').update(message).digest('hex') const data = `${url}-36cd479b6b5-${text}-36cd479b6b5-${digest}` return { - params: aesEncrypt(Buffer.from(data), 'ecb', eapiKey, '').toString('hex').toUpperCase() + params: aesEncrypt(Buffer.from(data), 'ecb', eapiKey, '') + .toString('hex') + .toUpperCase(), } } -const decrypt = cipherBuffer => { +const decrypt = (cipherBuffer) => { const decipher = crypto.createDecipheriv('aes-128-ecb', eapiKey, '') return Buffer.concat([decipher.update(cipherBuffer), decipher.final()]) } -module.exports = {weapi, linuxapi, eapi, decrypt} \ No newline at end of file +module.exports = { weapi, linuxapi, eapi, decrypt } diff --git a/util/index.js b/util/index.js index c6783f94ba9..4ecd4ec809c 100644 --- a/util/index.js +++ b/util/index.js @@ -4,13 +4,13 @@ module.exports = { return val === 'true' || val == '1' }, cookieToJson(cookie) { - if (!cookie ) return {} - let cookieArr = cookie.split(';'); - let obj = {} + if (!cookie) return {} + let cookieArr = cookie.split(';') + let obj = {} cookieArr.forEach((i) => { - let arr = i.split('='); - obj[arr[0]] = arr[1]; - }); + let arr = i.split('=') + obj[arr[0]] = arr[1] + }) return obj - } + }, } diff --git a/util/memory-cache.js b/util/memory-cache.js index 178530728a9..6b6deaa2a4d 100644 --- a/util/memory-cache.js +++ b/util/memory-cache.js @@ -2,58 +2,62 @@ function MemoryCache() { this.cache = {} this.size = 0 } - -MemoryCache.prototype.add = function(key, value, time, timeoutCallback) { + +MemoryCache.prototype.add = function (key, value, time, timeoutCallback) { var old = this.cache[key] var instance = this - + var entry = { value: value, expire: time + Date.now(), - timeout: setTimeout(function() { + timeout: setTimeout(function () { instance.delete(key) - return timeoutCallback && typeof timeoutCallback === 'function' && timeoutCallback(value, key) - }, time) + return ( + timeoutCallback && + typeof timeoutCallback === 'function' && + timeoutCallback(value, key) + ) + }, time), } - + this.cache[key] = entry this.size = Object.keys(this.cache).length - + return entry } - -MemoryCache.prototype.delete = function(key) { + +MemoryCache.prototype.delete = function (key) { var entry = this.cache[key] - + if (entry) { clearTimeout(entry.timeout) } - + delete this.cache[key] - + this.size = Object.keys(this.cache).length - + return null } - -MemoryCache.prototype.get = function(key) { + +MemoryCache.prototype.get = function (key) { var entry = this.cache[key] - + return entry } - -MemoryCache.prototype.getValue = function(key) { + +MemoryCache.prototype.getValue = function (key) { var entry = this.get(key) - + return entry && entry.value } - -MemoryCache.prototype.clear = function() { - Object.keys(this.cache).forEach(function(key) { + +MemoryCache.prototype.clear = function () { + Object.keys(this.cache).forEach(function (key) { this.delete(key) }, this) - + return true } - -module.exports = MemoryCache \ No newline at end of file + +module.exports = MemoryCache diff --git a/util/request.js b/util/request.js index fcf75bec0db..f7a5523e658 100644 --- a/util/request.js +++ b/util/request.js @@ -16,7 +16,7 @@ const chooseUserAgent = (ua = false) => { // iOS with qq micromsg 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML like Gecko) Mobile/14A456 QQ/6.5.7.408 V1_IPH_SQ_6.5.7_1_APP_A Pixel/750 Core/UIWebView NetType/4G Mem/103', 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.15(0x17000f27) NetType/WIFI Language/zh', - // Android -> Huawei Xiaomi + // Android -> Huawei Xiaomi 'Mozilla/5.0 (Linux; Android 9; PCT-AL10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.311 Mobile Safari/537.36', 'Mozilla/5.0 (Linux; U; Android 9; zh-cn; Redmi Note 8 Build/PKQ1.190616.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.141 Mobile Safari/537.36 XiaoMi/MiuiBrowser/12.5.22', // Android + qq micromsg @@ -31,12 +31,15 @@ const chooseUserAgent = (ua = false) => { // Windows 10 Firefox / Chrome / Edge 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.30 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586' + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586', // Linux 就算了 - ] + ], } - let realUserAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc) - return (['mobile', 'pc', false].indexOf(ua) > -1) ? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)] : ua + let realUserAgentList = + userAgentList[ua] || userAgentList.mobile.concat(userAgentList.pc) + return ['mobile', 'pc', false].indexOf(ua) > -1 + ? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)] + : ua } const createRequest = (method, url, data, options) => { return new Promise((resolve, reject) => { @@ -45,16 +48,15 @@ const createRequest = (method, url, data, options) => { headers['Content-Type'] = 'application/x-www-form-urlencoded' if (url.includes('music.163.com')) headers['Referer'] = 'https://music.163.com' - if (options.realIP) - headers['X-Real-IP'] = options.realIP + if (options.realIP) headers['X-Real-IP'] = options.realIP // headers['X-Real-IP'] = '118.88.88.88' if (typeof options.cookie === 'object') headers['Cookie'] = Object.keys(options.cookie) .map( - key => + (key) => encodeURIComponent(key) + '=' + - encodeURIComponent(options.cookie[key]) + encodeURIComponent(options.cookie[key]), ) .join('; ') else if (options.cookie) headers['Cookie'] = options.cookie @@ -71,35 +73,35 @@ const createRequest = (method, url, data, options) => { data = encrypt.linuxapi({ method: method, url: url.replace(/\w*api/, 'api'), - params: data + params: data, }) headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36' url = 'https://music.163.com/api/linux/forward' } else if (options.crypto === 'eapi') { - const cookie = options.cookie || {}; + const cookie = options.cookie || {} const csrfToken = cookie['__csrf'] || '' const header = { - 'osver': cookie.osver, //系统版本 - 'deviceId': cookie.deviceId, //encrypt.base64.encode(imei + '\t02:00:00:00:00:00\t5106025eb79a5247\t70ffbaac7') - 'appver': cookie.appver || '6.1.1', // app版本 - 'versioncode': cookie.versioncode || '140', //版本号 - 'mobilename': cookie.mobilename, //设备model - 'buildver': cookie.buildver || Date.now().toString().substr(0, 10), - 'resolution': cookie.resolution || '1920x1080', //设备分辨率 - '__csrf': csrfToken, - 'os': cookie.os || 'android', - 'channel': cookie.channel, - 'requestId': `${Date.now()}_${Math.floor(Math.random() * 1000).toString().padStart(4, '0')}` + osver: cookie.osver, //系统版本 + deviceId: cookie.deviceId, //encrypt.base64.encode(imei + '\t02:00:00:00:00:00\t5106025eb79a5247\t70ffbaac7') + appver: cookie.appver || '6.1.1', // app版本 + versioncode: cookie.versioncode || '140', //版本号 + mobilename: cookie.mobilename, //设备model + buildver: cookie.buildver || Date.now().toString().substr(0, 10), + resolution: cookie.resolution || '1920x1080', //设备分辨率 + __csrf: csrfToken, + os: cookie.os || 'android', + channel: cookie.channel, + requestId: `${Date.now()}_${Math.floor(Math.random() * 1000) + .toString() + .padStart(4, '0')}`, } if (cookie.MUSIC_U) header['MUSIC_U'] = cookie.MUSIC_U if (cookie.MUSIC_A) header['MUSIC_A'] = cookie.MUSIC_A headers['Cookie'] = Object.keys(header) .map( - key => - encodeURIComponent(key) + - '=' + - encodeURIComponent(header[key]) + (key) => + encodeURIComponent(key) + '=' + encodeURIComponent(header[key]), ) .join('; ') data.header = header @@ -112,7 +114,7 @@ const createRequest = (method, url, data, options) => { method: method, url: url, headers: headers, - body: queryString.stringify(data) + body: queryString.stringify(data), } if (options.crypto === 'eapi') settings.encoding = null @@ -123,62 +125,55 @@ const createRequest = (method, url, data, options) => { settings.proxy = options.proxy } - request( - settings, - (err, res, body) => { - if (err) { - answer.status = 502 - answer.body = { code: 502, msg: err.stack } - reject(answer) - } else { - answer.cookie = (res.headers['set-cookie'] || []).map(x => - x.replace(/\s*Domain=[^(;|$)]+;*/, '') - ) - try { - if (options.crypto === 'eapi') { - - zlib.unzip(body, function (err, buffer) { - const _buffer = err ? body : buffer + request(settings, (err, res, body) => { + if (err) { + answer.status = 502 + answer.body = { code: 502, msg: err.stack } + reject(answer) + } else { + answer.cookie = (res.headers['set-cookie'] || []).map((x) => + x.replace(/\s*Domain=[^(;|$)]+;*/, ''), + ) + try { + if (options.crypto === 'eapi') { + zlib.unzip(body, function (err, buffer) { + const _buffer = err ? body : buffer + try { try { - try { - answer.body = JSON.parse(encrypt.decrypt(_buffer).toString()) - answer.status = answer.body.code || res.statusCode - } catch (e) { - answer.body = JSON.parse(_buffer.toString()) - answer.status = res.statusCode - } + answer.body = JSON.parse(encrypt.decrypt(_buffer).toString()) + answer.status = answer.body.code || res.statusCode } catch (e) { - answer.body = _buffer.toString() + answer.body = JSON.parse(_buffer.toString()) answer.status = res.statusCode } - answer.status = - 100 < answer.status && answer.status < 600 ? answer.status : 400 - if (answer.status === 200) resolve(answer) - else reject(answer) - }); - return false - - } else { - - answer.body = JSON.parse(body) - answer.status = answer.body.code || res.statusCode - if (answer.body.code === 502) { - answer.status = 200 + } catch (e) { + answer.body = _buffer.toString() + answer.status = res.statusCode } + answer.status = + 100 < answer.status && answer.status < 600 ? answer.status : 400 + if (answer.status === 200) resolve(answer) + else reject(answer) + }) + return false + } else { + answer.body = JSON.parse(body) + answer.status = answer.body.code || res.statusCode + if (answer.body.code === 502) { + answer.status = 200 } - - } catch (e) { - answer.body = body - answer.status = res.statusCode } - - answer.status = - 100 < answer.status && answer.status < 600 ? answer.status : 400 - if (answer.status == 200) resolve(answer) - else reject(answer) + } catch (e) { + answer.body = body + answer.status = res.statusCode } + + answer.status = + 100 < answer.status && answer.status < 600 ? answer.status : 400 + if (answer.status == 200) resolve(answer) + else reject(answer) } - ) + }) }) }