修正fetch单词的拼写错误

pull/96/head
lyswhut 2019-09-22 10:08:37 +08:00
parent 58e61e0bda
commit bebf1906a2
20 changed files with 59 additions and 72 deletions

View File

@ -1,13 +0,0 @@
### 新增
- 新增音乐**聚合搜索**,目前支持酷我、酷狗、百度源搜索
- 新增代理功能
### 优化
- 优化从《梦里嫦娥》皮肤切换到其他皮肤时侧栏动画的切换效果
### 修复
- 修复试听列表没有歌曲时会显示列表加载中的Bug
- 修复切换歌单列表详情时的UI Bug

View File

@ -7,7 +7,7 @@ const tasks = []
mainOn('request', (event, options) => { mainOn('request', (event, options) => {
// console.log(args) // console.log(args)
if (!options) return if (!options) return
let index = fatchData(options, (err, resp) => { let index = fetchData(options, (err, resp) => {
tasks[index] = null tasks[index] = null
if (err) { if (err) {
console.log(err) console.log(err)
@ -27,7 +27,7 @@ mainOn('cancelRequest', (event, index) => {
tasks[index] = null tasks[index] = null
}) })
const fatchData = (options, callback) => pushTask(tasks, request(options.url, { const fetchData = (options, callback) => pushTask(tasks, request(options.url, {
method: options.method, method: options.method,
headers: options.headers, headers: options.headers,
Origin: options.origin, Origin: options.origin,

View File

@ -1,10 +1,10 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { requestMsg } from '../../message' import { requestMsg } from '../../message'
import { headers, timeout } from '../options' import { headers, timeout } from '../options'
const api_test = { const api_test = {
getMusicUrl(songInfo, type) { getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/url/bd/${songInfo.songmid}/${type}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/url/bd/${songInfo.songmid}/${type}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,

View File

@ -2,7 +2,7 @@ import leaderboard from './leaderboard'
import api_source from '../api-source' import api_source from '../api-source'
import musicInfo from './musicInfo' import musicInfo from './musicInfo'
import songList from './songList' import songList from './songList'
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import musicSearch from './musicSearch' import musicSearch from './musicSearch'
const bd = { const bd = {
@ -19,7 +19,7 @@ const bd = {
}, },
getLyric(songInfo) { getLyric(songInfo) {
const requestObj = this.getMusicInfo(songInfo) const requestObj = this.getMusicInfo(songInfo)
requestObj.promise = requestObj.promise.then(info => httpFatch(info.lrclink).promise.then(resp => resp.body)) requestObj.promise = requestObj.promise.then(info => httpFetch(info.lrclink).promise.then(resp => resp.body))
return requestObj return requestObj
}, },
// getLyric(songInfo) { // getLyric(songInfo) {

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
// import { formatPlayTime } from '../../index' // import { formatPlayTime } from '../../index'
// import jshtmlencode from 'js-htmlencode' // import jshtmlencode from 'js-htmlencode'
@ -66,7 +66,7 @@ export default {
requestObj: null, requestObj: null,
getData(url) { getData(url) {
if (this.requestObj) this.requestObj.cancelHttp() if (this.requestObj) this.requestObj.cancelHttp()
this.requestObj = httpFatch(url) this.requestObj = httpFetch(url)
return this.requestObj.promise return this.requestObj.promise
}, },
filterData(rawList) { filterData(rawList) {

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
export default { export default {
cache: {}, cache: {},
@ -6,7 +6,7 @@ export default {
if (this.cache[songmid]) { if (this.cache[songmid]) {
return { promise: Promise.resolve(this.cache[songmid]) } return { promise: Promise.resolve(this.cache[songmid]) }
} }
const requestObj = httpFatch(`https://musicapi.qianqian.com/v1/restserver/ting?method=baidu.ting.song.getSongLink&format=json&from=bmpc&version=1.0.0&version_d=11.1.6.0&songid=${songmid}&type=1&res=1&s_protocol=1&aac=2&project=tpass`) const requestObj = httpFetch(`https://musicapi.qianqian.com/v1/restserver/ting?method=baidu.ting.song.getSongLink&format=json&from=bmpc&version=1.0.0&version_d=11.1.6.0&songid=${songmid}&type=1&res=1&s_protocol=1&aac=2&project=tpass`)
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
// console.log(body) // console.log(body)
if (body.error_code == 22000) { if (body.error_code == 22000) {

View File

@ -1,6 +1,6 @@
// import '../../polyfill/array.find' // import '../../polyfill/array.find'
// import jshtmlencode from 'js-htmlencode' // import jshtmlencode from 'js-htmlencode'
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { formatPlayTime } from '../../index' import { formatPlayTime } from '../../index'
// import { debug } from '../../utils/env' // import { debug } from '../../utils/env'
// import { formatSinger } from './util' // import { formatSinger } from './util'
@ -13,7 +13,7 @@ export default {
allPage: 1, allPage: 1,
musicSearch(str, page) { musicSearch(str, page) {
if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp() if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp()
searchRequest = httpFatch(`http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.5.6&method=baidu.ting.search.merge&format=json&query=${encodeURIComponent(str)}&page_no=${page}&page_size=${this.limit}&type=0&data_source=0&use_cluster=1`) searchRequest = httpFetch(`http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.5.6&method=baidu.ting.search.merge&format=json&query=${encodeURIComponent(str)}&page_no=${page}&page_size=${this.limit}&type=0&data_source=0&use_cluster=1`)
return searchRequest.promise.then(({ body }) => body) return searchRequest.promise.then(({ body }) => body)
}, },
handleResult(rawData) { handleResult(rawData) {

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { formatPlayTime, toMD5 } from '../../index' import { formatPlayTime, toMD5 } from '../../index'
import CryptoJS from 'crypto-js' import CryptoJS from 'crypto-js'
@ -110,7 +110,7 @@ export default {
// 获取标签 // 获取标签
getTags() { getTags() {
if (this._requestObj_tags) this._requestObj_tags.cancelHttp() if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
this._requestObj_tags = httpFatch(this.getTagsUrl()) this._requestObj_tags = httpFetch(this.getTagsUrl())
return this._requestObj_tags.promise.then(({ body }) => { return this._requestObj_tags.promise.then(({ body }) => {
if (body.error_code !== this.successCode) return this.getTags() if (body.error_code !== this.successCode) return this.getTags()
return { return {
@ -143,7 +143,7 @@ export default {
// 获取列表数据 // 获取列表数据
getList(sortId, tagId, page) { getList(sortId, tagId, page) {
if (this._requestObj_list) this._requestObj_list.cancelHttp() if (this._requestObj_list) this._requestObj_list.cancelHttp()
this._requestObj_list = httpFatch( this._requestObj_list = httpFetch(
this.getListUrl(sortId, tagId, page) this.getListUrl(sortId, tagId, page)
) )
return this._requestObj_list.promise.then(({ body }) => { return this._requestObj_list.promise.then(({ body }) => {
@ -187,7 +187,7 @@ export default {
if (this._requestObj_listDetail) { if (this._requestObj_listDetail) {
this._requestObj_listDetail.cancelHttp() this._requestObj_listDetail.cancelHttp()
} }
this._requestObj_listDetail = httpFatch(this.getListDetailUrl(id, page)) this._requestObj_listDetail = httpFetch(this.getListDetailUrl(id, page))
return this._requestObj_listDetail.promise.then(({ body }) => { return this._requestObj_listDetail.promise.then(({ body }) => {
if (body.error_code !== this.successCode) return this.getListDetail(id, page) if (body.error_code !== this.successCode) return this.getListDetail(id, page)
let listData = this.filterData(body.result.songlist) let listData = this.filterData(body.result.songlist)

View File

@ -1,10 +1,10 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { requestMsg } from '../../message' import { requestMsg } from '../../message'
import { headers, timeout } from '../options' import { headers, timeout } from '../options'
const api_test = { const api_test = {
getMusicUrl(songInfo, type) { getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/url/kg/${songInfo._types[type].hash}/${type}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/url/kg/${songInfo._types[type].hash}/${type}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,
@ -15,7 +15,7 @@ const api_test = {
return requestObj return requestObj
}, },
getPic(songInfo) { getPic(songInfo) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/pic/kg/${songInfo.hash}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/pic/kg/${songInfo.hash}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,
@ -26,7 +26,7 @@ const api_test = {
return requestObj return requestObj
}, },
getLyric(songInfo) { getLyric(songInfo) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/lrc/kg/${songInfo.hash}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/lrc/kg/${songInfo.hash}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,

View File

@ -1,6 +1,6 @@
// import '../../polyfill/array.find' // import '../../polyfill/array.find'
// import jshtmlencode from 'js-htmlencode' // import jshtmlencode from 'js-htmlencode'
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { formatPlayTime, sizeFormate } from '../../index' import { formatPlayTime, sizeFormate } from '../../index'
// import { debug } from '../../utils/env' // import { debug } from '../../utils/env'
// import { formatSinger } from './util' // import { formatSinger } from './util'
@ -13,7 +13,7 @@ export default {
allPage: 1, allPage: 1,
musicSearch(str, page) { musicSearch(str, page) {
if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp() if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp()
searchRequest = httpFatch(`http://ioscdn.kugou.com/api/v3/search/song?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${this.limit}&showtype=10&plat=2&version=7910&tag=1&correct=1&privilege=1&sver=5`) searchRequest = httpFetch(`http://ioscdn.kugou.com/api/v3/search/song?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${this.limit}&showtype=10&plat=2&version=7910&tag=1&correct=1&privilege=1&sver=5`)
return searchRequest.promise.then(({ body }) => body) return searchRequest.promise.then(({ body }) => body)
}, },
handleResult(rawData) { handleResult(rawData) {

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { formatPlayTime, sizeFormate } from '../../index' import { formatPlayTime, sizeFormate } from '../../index'
export default { export default {
@ -89,7 +89,7 @@ export default {
getSongList(sortId, tagId, page) { getSongList(sortId, tagId, page) {
if (this._requestObj_list) this._requestObj_list.cancelHttp() if (this._requestObj_list) this._requestObj_list.cancelHttp()
this._requestObj_list = httpFatch( this._requestObj_list = httpFetch(
this.getSongListUrl(sortId, tagId, page) this.getSongListUrl(sortId, tagId, page)
) )
return this._requestObj_list.promise.then(({ body }) => { return this._requestObj_list.promise.then(({ body }) => {
@ -99,7 +99,7 @@ export default {
}, },
getSongListRecommend() { getSongListRecommend() {
if (this._requestObj_listRecommend) this._requestObj_listRecommend.cancelHttp() if (this._requestObj_listRecommend) this._requestObj_listRecommend.cancelHttp()
this._requestObj_listRecommend = httpFatch( this._requestObj_listRecommend = httpFetch(
'http://everydayrec.service.kugou.com/guess_special_recommend', 'http://everydayrec.service.kugou.com/guess_special_recommend',
{ {
method: 'post', method: 'post',
@ -140,7 +140,7 @@ export default {
getListDetail(id, page) { // 获取歌曲列表内的音乐 getListDetail(id, page) { // 获取歌曲列表内的音乐
if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp() if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp()
this._requestObj_listDetail = httpFatch(this.getSongListDetailUrl(id)) this._requestObj_listDetail = httpFetch(this.getSongListDetailUrl(id))
return this._requestObj_listDetail.promise.then(({ body }) => { return this._requestObj_listDetail.promise.then(({ body }) => {
let listData = body.match(this.regExps.listData) let listData = body.match(this.regExps.listData)
if (listData) listData = this.filterData(JSON.parse(RegExp.$1)) if (listData) listData = this.filterData(JSON.parse(RegExp.$1))
@ -211,7 +211,7 @@ export default {
// 获取列表信息 // 获取列表信息
getListInfo(tagId) { getListInfo(tagId) {
if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp() if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp()
this._requestObj_listInfo = httpFatch(this.getInfoUrl(tagId)) this._requestObj_listInfo = httpFetch(this.getInfoUrl(tagId))
return this._requestObj_listInfo.promise.then(({ body }) => { return this._requestObj_listInfo.promise.then(({ body }) => {
if (body.status !== 1) return this.getListInfo(tagId) if (body.status !== 1) return this.getListInfo(tagId)
return { return {
@ -248,7 +248,7 @@ export default {
// 获取标签 // 获取标签
getTags() { getTags() {
if (this._requestObj_tags) this._requestObj_tags.cancelHttp() if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
this._requestObj_tags = httpFatch(this.getInfoUrl()) this._requestObj_tags = httpFetch(this.getInfoUrl())
return this._requestObj_tags.promise.then(({ body }) => { return this._requestObj_tags.promise.then(({ body }) => {
if (body.status !== 1) return this.getTags() if (body.status !== 1) return this.getTags()
return { return {

View File

@ -1,9 +1,9 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { headers, timeout } from '../options' import { headers, timeout } from '../options'
const api_temp = { const api_temp = {
getMusicUrl(songInfo, type) { getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`http://tm.tempmusic.tk/url/kw/${songInfo.songmid}/${type}`, { const requestObj = httpFetch(`http://tm.tempmusic.tk/url/kw/${songInfo.songmid}/${type}`, {
method: 'get', method: 'get',
headers, headers,
timeout, timeout,

View File

@ -1,10 +1,10 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { requestMsg } from '../../message' import { requestMsg } from '../../message'
import { headers, timeout } from '../options' import { headers, timeout } from '../options'
const api_test = { const api_test = {
// getMusicUrl(songInfo, type) { // getMusicUrl(songInfo, type) {
// const requestObj = httpFatch(`http://45.32.53.128:3002/m/kw/u/${songInfo.songmid}/${type}`, { // const requestObj = httpFetch(`http://45.32.53.128:3002/m/kw/u/${songInfo.songmid}/${type}`, {
// method: 'get', // method: 'get',
// headers, // headers,
// timeout, // timeout,
@ -15,7 +15,7 @@ const api_test = {
// return requestObj // return requestObj
// }, // },
getMusicUrl(songInfo, type) { getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/url/kw/${songInfo.songmid}/${type}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/url/kw/${songInfo.songmid}/${type}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
export default { export default {
formatTime(time) { formatTime(time) {
@ -10,7 +10,7 @@ export default {
return `[ti:${songinfo.songName}]\n[ar:${songinfo.artist}]\n[al:${songinfo.album}]\n[by:]\n[offset:0]\n${lrclist ? lrclist.map(l => `[${this.formatTime(l.time)}]${l.lineLyric}\n`).join('') : '暂无歌词'}` return `[ti:${songinfo.songName}]\n[ar:${songinfo.artist}]\n[al:${songinfo.album}]\n[by:]\n[offset:0]\n${lrclist ? lrclist.map(l => `[${this.formatTime(l.time)}]${l.lineLyric}\n`).join('') : '暂无歌词'}`
}, },
getLyric(songId) { getLyric(songId) {
const requestObj = httpFatch(`http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${songId}`) const requestObj = httpFetch(`http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${songId}`)
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return this.transformLrc(body.data) return this.transformLrc(body.data)
}) })

View File

@ -1,8 +1,8 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
export default { export default {
getPic({ songmid }) { getPic({ songmid }) {
const requestObj = httpFatch(`http://artistpicserver.kuwo.cn/pic.web?corp=kuwo&type=rid_pic&pictype=500&size=500&rid=${songmid}`) const requestObj = httpFetch(`http://artistpicserver.kuwo.cn/pic.web?corp=kuwo&type=rid_pic&pictype=500&size=500&rid=${songmid}`)
requestObj.promise = requestObj.promise.then(({ body }) => body) requestObj.promise = requestObj.promise.then(({ body }) => body)
return requestObj return requestObj
}, },

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { formatPlayTime, decodeName } from '../../index' import { formatPlayTime, decodeName } from '../../index'
import { formatSinger } from './util' import { formatSinger } from './util'
@ -40,7 +40,7 @@ export default {
// 获取标签 // 获取标签
getTag() { getTag() {
if (this._requestObj_tags) this._requestObj_tags.cancelHttp() if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
this._requestObj_tags = httpFatch(this.tagsUrl) this._requestObj_tags = httpFetch(this.tagsUrl)
return this._requestObj_tags.promise.then(({ body }) => { return this._requestObj_tags.promise.then(({ body }) => {
if (body.code !== this.successCode) return this.getTag() if (body.code !== this.successCode) return this.getTag()
return this.filterTagInfo(body.data) return this.filterTagInfo(body.data)
@ -49,7 +49,7 @@ export default {
// 获取标签 // 获取标签
getHotTag() { getHotTag() {
if (this._requestObj_hotTags) this._requestObj_hotTags.cancelHttp() if (this._requestObj_hotTags) this._requestObj_hotTags.cancelHttp()
this._requestObj_hotTags = httpFatch(this.hotTagUrl) this._requestObj_hotTags = httpFetch(this.hotTagUrl)
return this._requestObj_hotTags.promise.then(({ body }) => { return this._requestObj_hotTags.promise.then(({ body }) => {
if (body.code !== this.successCode) return this.getHotTag() if (body.code !== this.successCode) return this.getHotTag()
return this.filterInfoHotTag(body.data[0].data) return this.filterInfoHotTag(body.data[0].data)
@ -87,7 +87,7 @@ export default {
} else { } else {
id = null id = null
} }
this._requestObj_list = httpFatch(this.getListUrl({ sortId, id, type, page })) this._requestObj_list = httpFetch(this.getListUrl({ sortId, id, type, page }))
return this._requestObj_list.promise.then(({ body }) => { return this._requestObj_list.promise.then(({ body }) => {
if (!id || type == '10000') { if (!id || type == '10000') {
if (body.code !== this.successCode) return this.getListUrl({ sortId, id, type, page }) if (body.code !== this.successCode) return this.getListUrl({ sortId, id, type, page })
@ -157,7 +157,7 @@ export default {
if (this._requestObj_listDetail) { if (this._requestObj_listDetail) {
this._requestObj_listDetail.cancelHttp() this._requestObj_listDetail.cancelHttp()
} }
this._requestObj_listDetail = httpFatch(this.getListDetailUrl(id, page)) this._requestObj_listDetail = httpFetch(this.getListDetailUrl(id, page))
return this._requestObj_listDetail.promise.then(({ body }) => { return this._requestObj_listDetail.promise.then(({ body }) => {
if (body.result !== 'ok') return this.getListDetail(id, page) if (body.result !== 'ok') return this.getListDetail(id, page)
return { return {

View File

@ -1,10 +1,10 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { requestMsg } from '../../message' import { requestMsg } from '../../message'
import { headers, timeout } from '../messoer' import { headers, timeout } from '../messoer'
const api_messoer = { const api_messoer = {
getMusicUrl(songInfo, type) { getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`https://v1.itooi.cn/tencent/url?id=${songInfo.strMediaMid}&quality=${type.replace(/k$/, '')}`, { const requestObj = httpFetch(`https://v1.itooi.cn/tencent/url?id=${songInfo.strMediaMid}&quality=${type.replace(/k$/, '')}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,

View File

@ -1,4 +1,4 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { b64DecodeUnicode } from '../../index' import { b64DecodeUnicode } from '../../index'
export default { export default {
@ -6,7 +6,7 @@ export default {
matchLrc: /.+"lyric":"([\w=+/]*)".+/, matchLrc: /.+"lyric":"([\w=+/]*)".+/,
}, },
getLyric(songmid) { getLyric(songmid) {
const requestObj = httpFatch(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=2001461048&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&platform=yqq`, { const requestObj = httpFetch(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=2001461048&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
headers: { headers: {
Referer: 'https://y.qq.com/portal/player.html', Referer: 'https://y.qq.com/portal/player.html',
}, },

View File

@ -1,10 +1,10 @@
import { httpFatch } from '../../request' import { httpFetch } from '../../request'
import { requestMsg } from '../../message' import { requestMsg } from '../../message'
import { headers, timeout } from '../options' import { headers, timeout } from '../options'
const api_test = { const api_test = {
getMusicUrl(songInfo, type) { getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/url/wy/${songInfo.songmid}/${type}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/url/wy/${songInfo.songmid}/${type}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,
@ -15,7 +15,7 @@ const api_test = {
return requestObj return requestObj
}, },
getPic(songInfo) { getPic(songInfo) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/pic/wy/${songInfo.songmid}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/pic/wy/${songInfo.songmid}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,
@ -26,7 +26,7 @@ const api_test = {
return requestObj return requestObj
}, },
getLyric(songInfo) { getLyric(songInfo) {
const requestObj = httpFatch(`http://ts.tempmusic.tk/lrc/wy/${songInfo.songmid}`, { const requestObj = httpFetch(`http://ts.tempmusic.tk/lrc/wy/${songInfo.songmid}`, {
method: 'get', method: 'get',
timeout, timeout,
headers, headers,

View File

@ -22,7 +22,7 @@ const buildHttpPromose = (url, options) => {
const p = new Promise((resolve, reject) => { const p = new Promise((resolve, reject) => {
cancelFn = reject cancelFn = reject
debugRequest && console.log(`\n---send request------${url}------------`) debugRequest && console.log(`\n---send request------${url}------------`)
requestObj = fatchData(url, options.method, options, (err, resp, body) => { requestObj = fetchData(url, options.method, options, (err, resp, body) => {
// options.isShowProgress && window.api.hideProgress() // options.isShowProgress && window.api.hideProgress()
debugRequest && console.log(`\n---response------${url}------------`) debugRequest && console.log(`\n---response------${url}------------`)
debugRequest && console.log(JSON.stringify(body)) debugRequest && console.log(JSON.stringify(body))
@ -31,7 +31,7 @@ const buildHttpPromose = (url, options) => {
if (err) { if (err) {
console.log(err.code) console.log(err.code)
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') { if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
const { promise, cancelHttp } = httpFatch(url, options) const { promise, cancelHttp } = httpFetch(url, options)
obj.cancelHttp = cancelHttp obj.cancelHttp = cancelHttp
promise.then() promise.then()
} }
@ -59,11 +59,11 @@ const buildHttpPromose = (url, options) => {
* @param {*} url * @param {*} url
* @param {*} options * @param {*} options
*/ */
export const httpFatch = (url, options = { method: 'get' }) => { export const httpFetch = (url, options = { method: 'get' }) => {
const requestObj = buildHttpPromose(url, options) const requestObj = buildHttpPromose(url, options)
requestObj.promise = requestObj.promise.catch(err => { requestObj.promise = requestObj.promise.catch(err => {
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') { if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
const { promise, cancelHttp } = httpFatch(url, options) const { promise, cancelHttp } = httpFetch(url, options)
requestObj.cancelHttp() requestObj.cancelHttp()
requestObj.cancelHttp = cancelHttp requestObj.cancelHttp = cancelHttp
return promise return promise
@ -106,7 +106,7 @@ export const http = (url, options, cb) => {
if (options.method == null) options.method = 'get' if (options.method == null) options.method = 'get'
debugRequest && console.log(`\n---send request------${url}------------`) debugRequest && console.log(`\n---send request------${url}------------`)
return fatchData(url, options.method, options, (err, resp, body) => { return fetchData(url, options.method, options, (err, resp, body) => {
// options.isShowProgress && window.api.hideProgress() // options.isShowProgress && window.api.hideProgress()
debugRequest && console.log(`\n---response------${url}------------`) debugRequest && console.log(`\n---response------${url}------------`)
debugRequest && console.log(JSON.stringify(body)) debugRequest && console.log(JSON.stringify(body))
@ -135,7 +135,7 @@ export const httpGet = (url, options, callback) => {
// }) // })
debugRequest && console.log(`\n---send request-------${url}------------`) debugRequest && console.log(`\n---send request-------${url}------------`)
return fatchData(url, 'get', options, function(err, resp, body) { return fetchData(url, 'get', options, function(err, resp, body) {
// options.isShowProgress && window.api.hideProgress() // options.isShowProgress && window.api.hideProgress()
debugRequest && console.log(`\n---response------${url}------------`) debugRequest && console.log(`\n---response------${url}------------`)
debugRequest && console.log(JSON.stringify(body)) debugRequest && console.log(JSON.stringify(body))
@ -166,7 +166,7 @@ export const httpPost = (url, data, options, callback) => {
options.data = data options.data = data
debugRequest && console.log(`\n---send request-------${url}------------`) debugRequest && console.log(`\n---send request-------${url}------------`)
return fatchData(url, 'post', options, function(err, resp, body) { return fetchData(url, 'post', options, function(err, resp, body) {
// options.isShowProgress && window.api.hideProgress() // options.isShowProgress && window.api.hideProgress()
debugRequest && console.log(`\n---response------${url}------------`) debugRequest && console.log(`\n---response------${url}------------`)
debugRequest && console.log(JSON.stringify(body)) debugRequest && console.log(JSON.stringify(body))
@ -203,7 +203,7 @@ export const http_jsonp = (url, options, callback) => {
// }) // })
debugRequest && console.log(`\n---send request-------${url}------------`) debugRequest && console.log(`\n---send request-------${url}------------`)
return fatchData(url, 'get', options, function(err, resp, body) { return fetchData(url, 'get', options, function(err, resp, body) {
// options.isShowProgress && window.api.hideProgress() // options.isShowProgress && window.api.hideProgress()
debugRequest && console.log(`\n---response------${url}------------`) debugRequest && console.log(`\n---response------${url}------------`)
debugRequest && console.log(JSON.stringify(body)) debugRequest && console.log(JSON.stringify(body))
@ -221,7 +221,7 @@ const getProxyInfo = () => window.globalObj.proxy.enable
? `http://${window.globalObj.proxy.username}:${window.globalObj.proxy.password}@${window.globalObj.proxy.host}:${window.globalObj.proxy.port};` ? `http://${window.globalObj.proxy.username}:${window.globalObj.proxy.password}@${window.globalObj.proxy.host}:${window.globalObj.proxy.port};`
: undefined : undefined
const fatchData = (url, method, options, callback) => { const fetchData = (url, method, options, callback) => {
// console.log(url, options) // console.log(url, options)
console.log('---start---', url) console.log('---start---', url)
if (options.headers && options.headers[bHh]) { if (options.headers && options.headers[bHh]) {