Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed May 29, 2022
1 parent 065d4aa commit 6bd63eb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions module/homepage_dragon_ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// !需要登录或者匿名登录,非登录返回 []
const config = require('../util/config.json')
module.exports = (query, request) => {
if (!('MUSIC_U' in query.cookie))
query.cookie.MUSIC_A = config.anonymous_token
const data = {}
query.cookie.os = 'ios'
query.cookie.appver = '8.7.01'
Expand Down
2 changes: 0 additions & 2 deletions module/simi_artist.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 相似歌手
const config = require('../util/config.json')
module.exports = (query, request) => {
if (!('MUSIC_U' in query.cookie))
query.cookie.MUSIC_A = config.anonymous_token
const data = {
artistid: query.id,
}
Expand Down
2 changes: 1 addition & 1 deletion util/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"anonymous_token": "8aae43f148f990410b9a2af38324af24e87ab9227c9265627ddd10145db744295fcd8701dc45b1ab8985e142f491516295dd965bae848761274a577a62b0fdc54a50284d1e434dcc04ca6d1a52333c9a",
"anonymous_token": "8aae43f148f990410b9a2af38324af24e87ab9227c9265627ddd10145db744295fcd8701dc45b1ab8985e142f491516295dd965bae848761274a577a62b0fdc54a50284d1e434dcc04ca6",
"resourceTypeMap": {
"0": "R_SO_4_",
"1": "R_MV_5_",
Expand Down
7 changes: 7 additions & 0 deletions util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ module.exports = {
})
return obj
},
getRandom(num) {
var random = Math.floor(
(Math.random() + Math.floor(Math.random() * 9 + 1)) *
Math.pow(10, num - 1),
)
return random
},
}
4 changes: 2 additions & 2 deletions util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const https = require('https')
const tunnel = require('tunnel')
const { URLSearchParams, URL } = require('url')
const config = require('../util/config.json')
const { getRandom } = require('../util')
// request.debug = true // 开启可看到更详细信息

const chooseUserAgent = (ua = false) => {
Expand Down Expand Up @@ -54,7 +55,7 @@ const createRequest = (method, url, data, options) => {
if (typeof options.cookie === 'object') {
if (!options.cookie.MUSIC_U) {
// 匿名
options.cookie.MUSIC_A = config.anonymous_token
options.cookie.MUSIC_A = config.anonymous_token + getRandom(10)
}
headers['Cookie'] = Object.keys(options.cookie)
.map(
Expand Down Expand Up @@ -112,7 +113,6 @@ const createRequest = (method, url, data, options) => {
data = encrypt.eapi(options.url, data)
url = url.replace(/\w*api/, 'eapi')
}

const answer = { status: 500, body: {}, cookie: [] }
let settings = {
method: method,
Expand Down

0 comments on commit 6bd63eb

Please sign in to comment.