add limit

This commit is contained in:
rainerosion 2023-08-10 22:22:49 +08:00
parent 514c658984
commit c769c7966c
3 changed files with 705 additions and 275 deletions

798
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,8 @@
"dependencies": {
"axios": "^1.4.0",
"express": "^4.18.2",
"nedb": "^1.8.0",
"nodemon": "^3.0.1",
"qs": "^6.11.2",
"text-encoding": "^0.7.0"
"qs": "^6.11.2"
}
}

178
rest.js
View File

@ -1,75 +1,137 @@
const express = require("express");
const axios = require("axios");
const qs = require("qs");
const NeDB = require('nedb')
const app = express();
const port = 25362;
app.get('/submit', async (req, res) => {
let uid = req.query.uid;
let mile = req.query.mile;
let ua = req.query.userAgent;
if (!uid || !mile) {
res.status(400).send({
code: 400,
info: '参数uid或mile不能为空。'
});
return;
}
const currentTimestamp = new Date().getTime(); // 或者使用 Date.now()
console.log("uid => " + uid + ",timestamp => " + currentTimestamp);
let userInfo = {
"isBack": 0,
"mile": mile,
"userId": uid,
"timestamp": currentTimestamp
};
const param = Buffer.from(JSON.stringify(userInfo)).toString('base64');
console.log(param);
let data = qs.stringify({
'param': param
});
let config = {
headers:{
'Host': 'herobox.yingxiong.com:25362',
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'Source': 'h5',
'User-Agent': getUA(uid, ua),
'Version': '2.16.1',
'Origin': 'https://herobox.yingxiong.com:8022',
'X-Requested-With': 'com.hero.time',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://herobox.yingxiong.com:8022/',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7'
}
};
let response = await axios.post('https://herobox.yingxiong.com:25362/encourage/flappy/calc', data, config);
console.log(JSON.stringify(response.data));
if (response.status === 200 && response.data.code === 200) {
res.send({
code: 200,
high: response.data.data.highMile,
total: response.data.data.totalMile
});
return;
}
res.send({
code: 500,
info: response.data.msg
});
const db = new NeDB({
filename: './user.db',
autoload: true,
});
const findData = (uid) => {
return new Promise((resolve, reject) => {
db.find({"uid": uid}, (err, columns) => {
if (err) {
reject(err);
} else {
resolve(columns);
}
});
});
};
app.get('/submit', async (req, res) => {
try {
let uid = req.query.uid;
let mile = req.query.mile;
let ua = req.query.userAgent;
if (!uid || !mile) {
res.status(400).send({
code: 400,
info: '参数uid或mile不能为空。'
});
return;
}
const currentTimestamp = new Date().getTime(); // 或者使用 Date.now()
let existUid = false;
let waitTime = 0;
// 查询数据是否存在
const columns = await findData(uid);
let _id;
console.log(columns);
if (columns && columns.length >= 1) {
existUid = true;
let column = columns[0];
_id = column._id;
waitTime = (column.lastTime - currentTimestamp) / 1000;
}
if (waitTime > 0) {
res.status(400).send({
code: 401,
info: `等待${parseInt(waitTime)}秒后才能继续执行该账号!`
});
return;
}
// console.log("uid => " + uid + ",timestamp => " + currentTimestamp);
let userInfo = {
"isBack": 0,
"mile": mile,
"userId": uid,
"timestamp": currentTimestamp
};
const param = Buffer.from(JSON.stringify(userInfo)).toString('base64');
// console.log(param);
let data = qs.stringify({
'param': param
});
let config = {
headers: {
'Host': 'herobox.yingxiong.com:25362',
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'Source': 'h5',
'User-Agent': getUA(uid, ua),
'Version': '2.16.1',
'Origin': 'https://herobox.yingxiong.com:8022',
'X-Requested-With': 'com.hero.time',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://herobox.yingxiong.com:8022/',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7'
}
};
let response = await axios.post('https://herobox.yingxiong.com:25362/encourage/flappy/calc', data, config);
console.log(JSON.stringify(response.data));
if (response.status === 200 && response.data.code === 200 && response.data.data) {
if (!existUid) {
db.insert({
uid: uid,
timestamp: currentTimestamp,
lastTime: currentTimestamp + ((mile * 4) * 1000)
}, () => console.log("数据已记录"));
} else {
db.update({"_id": _id}, {
$set: {
timestamp: currentTimestamp,
lastTime: (currentTimestamp + ((mile * 4) * 1000))
}
}, {multi: false}, () => console.log("数据已更新"));
}
res.send({
code: 200,
high: response.data.data.highMile,
total: response.data.data.totalMile
});
return;
}
res.send({
code: 500,
info: response.data.msg
});
} catch (e) {
console.log("发生错误,原因:" + e.message);
res.status(500).send({
code: 501,
info: e.message
});
}
});
function getUA(uid, ua) {
if (ua) {
return ua;
} else {
let mode = ["NX569J","RMX1991","RMX3561","NX569H","NX569J","RMX1991","PD2208","NX569H","NX569J","RMX3561"]
let mode = ["NX569J", "RMX1991", "RMX3561", "NX569H", "NX569J", "RMX1991", "PD2208", "NX569H", "NX569J", "RMX3561"]
return `Mozilla/5.0 (Linux; Android 13; ${mode[uid.charAt(5)]}} Build/AC1A.220${uid.charAt(3)}0${uid.charAt(6)}.0${uid.slice(7, 9)}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36CP6.TgzO Hero/2.18.0`;
}
}
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});