const rq = (type, name, page) => { if (page) { return request(`http://mp3.zing.vn/nghe-si/${name}/${type}?&page=${page}`); } return request(`http://mp3.zing.vn/nghe-si/${name}/${type}`); };
co(function* () { const html = yield request(`http://mp3.zing.vn/album/${title}/${id}.html`); const regex = /media\/get-source\?type=album&key=.{33}/; // get the resouce url const match = html.match(regex); if (!match) throw new Error("can't find the resource URL"); const [playlistUrl] = match; const parser = new Scraper(html); return yield Promise.all([ request(`https://mp3.zing.vn/xhr/${playlistUrl}`), promiseParsing(parser), ]); })
export async function update (params) { return request({ url: user, method: 'patch', data: params, }) }
export async function create (params) { return request({ url: users, method: 'post', data: params, }) }
export function login (data) { return request({ url: userLogin, method: 'post', data, }) }
export async function query (params) { return request({ url: user.replace('/:id', ''), method: 'get', data: params, }) }
export function query (params) { return request({ url: posts, method: 'get', data: params, }) }
export function query (params) { return request({ url: dashboard, method: 'get', data: params, }) }
export async function query (params) { return request({ url: users, method: 'get', data: params, }) }
export async function query(params) { return request({ url: config.api.permissions, method: 'get', data: params }) }
module.exports = function getDefaultArtists(req, res, next) { request('http://mp3.zing.vn/the-loai-nghe-si') .then(html => { const parser = new PageScraper(html); const result = parser .list('.zcontent .title-section') .setKey('origin') .extractAttrs(['text', 'href'], 'a', ['title', 'id']) .get(); // result.origins is now available // minimize html html = parser.$('.zcontent').html(); result.origins = result.origins.map((origin, index) => { const innerParser = new PageScraper(html); // rewrite the parser elements innerParser.elements = parser.list('.row.fn-list').elements.eq(index).find('.artist-item'); innerParser .setKey('artist') // the key will be artists .extractAttr('src', 'img', 'thumb') .extractAttrs(['href', 'text'], 'a.txt-primary', ['link', 'name']); return Object.assign(origin, innerParser.get()); }); res.json(Object.assign({ result: true }, result)); }) .catch(err => next(err)); };
export async function login (params) { return request({ url: userLogin, method: 'post', data: params, }) }
export async function logout (params) { return request({ url: userLogout, method: 'get', data: params, }) }
export function query (params) { params.key = 'i7sau1babuzwhycn' return request({ url: `${APIV1}/weather/now.json`, method: 'get', data: params, }) }
export async function remove (params) { console.log('params', params) return request({ url: user, method: 'delete', data: params, }) }
export async function remove (params) { console.log('users remove param', params) return request({ url: `${users}/${params.ids[0]}`, method: 'delete', data: params, }) }
export async function query (params) { console.log('user query params', params) return request({ url: `${users}/${params.id}`, method: 'get', data: params, }) }
module.exports = function getSuggestedSongs(req, res, next) { const { songId, artistId } = req.query; const url = `https://mp3.zing.vn/xhr/recommend?target=%23block-recommend&count=20&start=0&artistid=${artistId}&type=audio&id=${songId}`; request(url) .then(body => { const data = JSON.parse(body); res.json(data); }) .catch(err => next(err)); };
module.exports = function (req, res, next) { const { id } = req.params; request(`http://mp3.zing.vn/json/charts?op=get&type=song&id=${id}`) .then(data => { // redisClient.set(getRedisKey(req), data, 'EX', 60 * 60 * 24 * 5); res.json(JSON.parse(data)); }) .catch(err => next(err)); };
co(function* () { const html = yield request(`https://mp3.zing.vn/bai-hat/${name}/${id}.html`); const regex = /media\/get-source\?type=audio&key=.{33}/; // get the resouce url const match = html.match(regex); if (!match) throw new Error("can't find the resource URL"); const [matchUrl] = match; const resource = yield request(`https://mp3.zing.vn/xhr/${matchUrl}`); const data = JSON.parse(resource).data; // data.lyric now is a url if (!data.lyric.trim()) { data.lyric = []; // rewrite the {string} url to an array return data; } const lrcFile = yield request(data.lyric); data.lyric = lrcParser(lrcFile).scripts; return data; })
componentDidMount() { if (this.props.data.length > 0) { this.initData(this.props.data); } else if (this.props.url) { request({ url: this.props.url, method: 'GET' }).then(data => { this.initData(data); }) } }
changePass() { let pass = this.state.pass; if (!pass['newPass'] || pass['newPass'].length < 6) { message.error("密码长度不能小于6位"); return; } if (pass['newPass'] != pass['confirmPass']) { message.error("两次输入密码不一致"); return; } request({ url: '/sys/user/changePass', method: 'POST', data: pass }).then(() => { message.info("密码重置成功"); this.setState({ passModalVisible: false }) }) }
initFileFields(value) { if (util.string.isEmpty(value)) value = ''; let self = this; let fileArr = []; let fileNameMap = self.state.fileNameMap; let paths = value.split(',').filter(p => !util.string.isEmpty(p)); fileArr = paths.map((p) => { let ext = p.substring(p.lastIndexOf('.')); return { uid: p, name: fileNameMap[p] || 'file' + ext, status: 'done', url: p, thumbUrl: p } }); this.setState({ fileList: fileArr }); //显示文件名 for (let path of paths) { if (!fileNameMap[path]) { request({ url: config.api.getFileName + path, method: 'get' }).then(function (fileName) { let file = fileArr.find(p => p.url === path); file.name = fileName; fileNameMap[path] = fileName; self.setState({ fileList: fileArr, fileNameMap: fileNameMap }) }) } } }
fetch = () => { const { fetch: { url, data, dataKey } } = this.props const { fetchData } = this.state this.setState({ loading: true }) this.promise = request({ url, data: { ...data, ...fetchData, }, }).then((result) => { if (!this.refs.DataTable) { return } const { pagination } = this.state pagination.total = result.total || pagination.total this.setState({ loading: false, dataSource: dataKey ? result[dataKey] : result.data, pagination, }) }) }
export async function myCity (params) { return request({ url: 'http://www.zuimeitianqi.com/zuimei/myCity', data: params, }) }
export async function queryWeather (params) { return request({ url: 'http://www.zuimeitianqi.com/zuimei/queryWeather', data: params, }) }
const login = (data) => request({ url: API.login, method: 'post', data })
const check = () => request({ url: API.tokenVerify, method: 'get', token: true })
const logout = () => request({ url: API.logout, method: 'get', token: true })