1 Star 0 Fork 0

Cherokee/anyproxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tfcaijing.js 2.90 KB
一键复制 编辑 原始数据 按行查看 历史
Cherokee 提交于 2019-09-26 17:07 . wip
const urlUtil = require('url');
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const adapter = new FileSync('db/tfcaijing.json');
const db = low(adapter);
db.defaults({ 'columns': {}, 'column_reqs': {}, 'updated': 0 }).write();
const columns = {};
const column_list_req_url = 'https://crab.tfcaijing.com/app/news/newsflashcolumn/list';
const column_detail_req_url = 'https://crab.tfcaijing.com/app/news/newsflash/listByColumnId';
//anyproxy refer: https://github.com/alibaba/anyproxy/tree/master/rule_sample
module.exports = {
summary: 'a rule to hack response',
* beforeSendRequest(requestDetail) {
if (requestDetail.url.startsWith(column_detail_req_url)) {
let urlobj = new URL(requestDetail.url);
let columnId = urlobj.searchParams.get('columnId');
if(columnId && columns[columnId]){
let columnName = columns[columnId];
let pageNum = urlobj.searchParams.get('pageNum');
let pageSize = urlobj.searchParams.get('pageSize');
let newRequestOptions = requestDetail.requestOptions;
let headers = newRequestOptions.headers;
let systemVersion = headers['systemVersion'];
let systemId = headers['systemId'];
let sign = headers['sign'];
db.set('column_reqs.'+columnName, {
'headers':{
systemVersion,
systemId,
sign
},
'query':{
columnId,
pageNum,
pageSize
},
'curl':`curl --request GET --url 'https://crab.tfcaijing.com/app/news/newsflash/listByColumnId?columnId=${columnId}&pageNum=1&pageSize=10' --header 'sign: ${sign}' --header 'systemid: ${systemId}' --header 'systemversion: ${systemVersion}'`,
'updated':new Date()
}).write();
}
/*
return {
requestOptions: newRequestOptions
};
*/
}
},
* beforeSendResponse(requestDetail, responseDetail) {
if (requestDetail.url.startsWith(column_list_req_url)) {
let newResponse = responseDetail.response;
let body = newResponse.body.toString();
try {
let json_data = JSON.parse(body);
if (json_data['data'] && json_data['data'].length > 0) {
for (let c of json_data['data']) {
columns[c['columnUid']] = c['columnTitle'];
}
db.set('columns', columns).write();
db.set('updated', new Date()).write();
}
} catch (e) {
}
/*
return new Promise((resolve, reject) => {
// setTimeout(() => { // delay
resolve({ response: newResponse });
// }, 1000);
});
*/
}
},
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/dreamidea/anyproxy.git
[email protected]:dreamidea/anyproxy.git
dreamidea
anyproxy
anyproxy
master

搜索帮助