Merge pull request #9 from lxmusics/dev

fix
This commit is contained in:
Folltoshe 2023-06-10 13:55:34 +08:00 committed by GitHub
commit 94e49eba05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 15 deletions

View File

@ -43,7 +43,7 @@ export default {
}, },
}, },
}).then(body => { }).then(body => {
if (body.req_1 != 0 || body.req_2 != 0 || body.req_3 != 0) throw new Error('get singer info faild.') if (!body.req_1 || !body.req_2 || !body.req_3) throw new Error('get singer info faild.')
const info = body.req_1.singer_list[0] const info = body.req_1.singer_list[0]
const music = body.req_3 const music = body.req_3

View File

@ -1,17 +1,6 @@
import { httpFetch } from '../../../request' import { httpFetch } from '../../../request'
import { eapi } from './crypto' import { eapi } from './crypto'
const buildEapiRequest = (formData) => {
return httpFetch('http://interface.music.163.com/eapi/batch', {
method: 'POST',
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
origin: 'https://music.163.com',
},
form: formData,
})
}
export const eapiRequest = (url, data) => { export const eapiRequest = (url, data) => {
return httpFetch('http://interface.music.163.com/eapi/batch', { return httpFetch('http://interface.music.163.com/eapi/batch', {
method: 'post', method: 'post',
@ -33,18 +22,17 @@ export const eapiRequest = (url, data) => {
} }
/** /**
* 创建一个适用于WY的Eapi请求 * 创建一个Eapi请求
* @param {*} url * @param {*} url
* @param {*} options * @param {*} options
* @param {*} retryNum * @param {*} retryNum
*/ */
export const createEapiFetch = async(url, data, retryNum = 0) => { export const createEapiFetch = async(url, data, retryNum = 0) => {
if (retryNum > 2) throw new Error('try max num') if (retryNum > 2) throw new Error('try max num')
const formData = eapi(url, data)
let result let result
try { try {
result = await buildEapiRequest(formData).promise result = await eapiRequest(url, data).promise
} catch (err) { } catch (err) {
console.log(err) console.log(err)
return createEapiFetch(url, data, ++retryNum) return createEapiFetch(url, data, ++retryNum)