Update README & Fix proxy bug & plan directory

This commit is contained in:
rccoder
2016-06-30 23:53:38 +08:00
parent 2093fea6a1
commit f4c1b6ccb5
12 changed files with 164 additions and 100 deletions
+58
View File
@@ -0,0 +1,58 @@
import request from 'request'
import { origin, globalOption } from './config'
import { deepCopy } from './util'
let api = {
search: (name = null, callback = null, limit = 3, offset = 0) => {
let option = deepCopy(globalOption)
let url = origin + '/api/search/suggest/web'
let form = {
s: name,
limit,
type: 1,
offset
}
let method = 'POST'
let proxy = false
Object.assign(option, { url, form, method, proxy })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
} else {
console.log(error)
}
})
},
song: (id, callback = null) => {
let option = deepCopy(globalOption)
let url = origin + '/api/song/detail?ids=%5B' + id + '%5d'
let method = 'GET'
let proxy = false
Object.assign(option, { url, method, proxy })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
} else {
console.log(error)
}
})
},
lrc: (id, callback = null, lv = -1) => {
let option = deepCopy(globalOption)
let url = origin + '/api/song/lyric?lv=' + lv + '&id=' + id
let method = 'GET'
let proxy = false
Object.assign(option, { url, method, proxy })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
} else {
console.log(error)
}
})
}
}
export {api}
+11
View File
@@ -0,0 +1,11 @@
const origin = 'http://music.163.com'
const globalOption = {
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
export { origin, globalOption }
+3
View File
@@ -0,0 +1,3 @@
const deepCopy = (obj) => JSON.parse(JSON.stringify(obj))
export { deepCopy }