From b57dc396219d48b079aadcb84deb3dc5e793e884 Mon Sep 17 00:00:00 2001 From: Hans362 Date: Wed, 10 Feb 2021 19:58:09 +0800 Subject: [PATCH] :sparkles: Version 1.0.0 --- api/now.js | 9 +++++++ lib/app.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 api/now.js create mode 100644 lib/app.js diff --git a/api/now.js b/api/now.js new file mode 100644 index 0000000..96e3ff6 --- /dev/null +++ b/api/now.js @@ -0,0 +1,9 @@ +const path = require('path'); +const moduleAlias = require('module-alias'); +moduleAlias.addAlias('@', path.join(__dirname, '../lib')); + +const app = require('../lib/app'); + +module.exports = (req, res) => { + app.callback()(req, res); +}; diff --git a/lib/app.js b/lib/app.js new file mode 100644 index 0000000..0cb5f4c --- /dev/null +++ b/lib/app.js @@ -0,0 +1,72 @@ +const http = require('http'); +const url = require('url'); +const express = require('express'); +const app = express(); + +const myhost = "api.bilibili.com"; + +class Url { + getParam(data) { + let url = ''; + for (var k in data) { + let value = data[k] !== undefined ? data[k] : ''; + url += `&${k}=${encodeURIComponent(value)}` + } + return url ? url.substring(1) : '' + } + getUrl(url, data) { + return url += (url.indexOf('?') < 0 ? '?' : '') + this.getParam(data) + } +} + +function nodePostGetRequest(HOST, PORT, method, bodydata, callBackFunction, path, cookie, ressss) { + var body = bodydata; + var bodyString = JSON.stringify(body); + var headers = { + 'Content-Type': 'application/json', + 'Content-Length': bodyString.length, + 'Cookie': cookie + }; + var options = { + host: HOST, + port: PORT, + path: path, + method: method, + headers: headers + }; + var req = http.request(options, function (res) { + res.setEncoding('utf-8'); + var responseString = ''; + res.on('data', function (data) { + responseString += data; + }); + res.on('end', function () { + let resultObject = JSON.parse(responseString); + getsuccess(resultObject, ressss); + }); + req.on('error', function (e) { + console.log('-----error-------', e); + }); + }); + req.write(bodyString); + req.end(); +} + +function getsuccess(data, res) { + res.send(data); +} + +app.get('/list', (req, res) => { + const type = req.query.type || "1"; + const pn = req.query.pn || "1"; + const ps = req.query.ps || "10"; + const vmid = req.query.vmid || "66745436"; + const num = 28; + const mycookie = req.query.cookies || "cookies"; + let URL = new Url(); + let mypath = URL.getUrl("/x/space/bangumi/follow/list", { type: type, pn: pn, ps: ps, vmid: vmid }); + console.log(mypath); + nodePostGetRequest(myhost, 80, 'GET', null, getsuccess, mypath, mycookie, res); +}); + +module.exports = app; \ No newline at end of file