queenshow-api

node v8.9.3
version: 1.1.2
endpointsharetweet
皇后秀API
var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); const bodyParser = require('body-parser'); const _ = require('lodash'); const axios = require('axios'); const xml2js = require('xml2js'); const parseString = xml2js.parseString; app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));
API地址
// API地址 const apiHost = 'https://www.queenshow.org'; const apiKey = 'd5eaa7d6fe64703f934eca2384a04b4a'; const APIs = { // 最新更新 newest: '/mobsvc/latest.php', // 所有免费分类 categories: '/mobsvc/main2.php', // 分类下帖子列表 lists: '/mobsvc/catalog.php' };
封装http请求方法
// 封装http请求方法 /*创建axios实例*/ const httpRequest = axios.create({ baseURL: apiHost, responseType:'text', headers:{ 'Host': 'www.queenshow.org', 'User-Agent': 'Dalvik/2.0.0 (Linux; U; Android 4.4.4; XT1080 Build/SU6-7)' } }); // 获取最新更新 function getNewest(page) { return httpRequest.get(APIs.newest,{ params: { key: apiKey, page: page || '1' } }) } // 获取所有分类 function getCategories() { return httpRequest.get(APIs.categories,{ params:{ key: apiKey }, }) } // 获取列表 function getListData(cataId,page) { return httpRequest.get(APIs.lists,{ params:{ key: apiKey, cataId: cataId || '103', page: page || '1' }, }) }
路由列表
// 路由列表 app.get('/', function (req, res) { res.json({msg: 'ack'}) }); app.get('/api/v1/newest', function (req, res) { let page = req.query.page || '1'; getNewest(page) .then(function (response) { let xml = response.data; xml = xml.replace(/&/g,'&'); parseString( xml, function (err, json) { if(err){ console.log(err); return res.send(err.message) ; } return res.send(json) ; }) }) .catch(function (error) { console.log(error); return res.send(error.message) ; }) }); app.get('/api/v1/categories', function (req, res) { getCategories() .then(function (response) { let xml = response.data; xml = xml.replace(/&/g,'&'); parseString( xml, function (err, json) { if(err){ console.log(err); return res.send(err.message) ; } return res.send(json) ; /* let lists = json.root && json.root.list && json.root.list[0].object; let filterList = []; lists.forEach(function(item,index){ if(item.contType[0] == 'img'){ filterList.push({ id: item.id[0], name: item.name[0].replace(/^[^-]*-/,''), ifFree: item.ifFree[0] }) } }) return res.send(filterList) ; */ }) }) .catch(function (error) { console.log(error); return res.send(error.message) ; }) }); app.get('/api/v1/lists', function (req, res) { let cataId = req.query.cataId || ''; let page = req.query.page || '1'; getListData(cataId,page) .then(function (response) { let xml = response.data; xml = xml.replace(/&/g,'&'); parseString( xml, function (err, json) { if(err){ console.log(err); return res.send(err.message) ; } return res.send(json) ; }) }) .catch(function (error) { console.log(error); return res.send(error.message) ; }) });
Loading…

no comments

    sign in to comment