Update server.js
Browse files
server.js
CHANGED
|
@@ -20,6 +20,7 @@ if (!fs.existsSync(CODES_FILE)) {
|
|
| 20 |
}
|
| 21 |
|
| 22 |
const AMOUNTS_FILE = "amounts.json";
|
|
|
|
| 23 |
|
| 24 |
// Function to get current Unix timestamp
|
| 25 |
function getUnixTimestamp() {
|
|
@@ -118,6 +119,49 @@ app.get("/api/get", (req, res) => {
|
|
| 118 |
res.json({ chatId, codes: codes[chatId] });
|
| 119 |
});
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
// Start server
|
| 122 |
app.listen(PORT, () => {
|
| 123 |
console.log(`Server running on port ${PORT}`);
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
const AMOUNTS_FILE = "amounts.json";
|
| 23 |
+
const AMOUNTS_FILE_2 = "amounts2.json";
|
| 24 |
|
| 25 |
// Function to get current Unix timestamp
|
| 26 |
function getUnixTimestamp() {
|
|
|
|
| 119 |
res.json({ chatId, codes: codes[chatId] });
|
| 120 |
});
|
| 121 |
|
| 122 |
+
app.get("/add2", (req, res) => {
|
| 123 |
+
const chatId = req.query.chatid;
|
| 124 |
+
const amount = parseInt(req.query.amount, 10);
|
| 125 |
+
|
| 126 |
+
if (!chatId || isNaN(amount) || amount <= 0) {
|
| 127 |
+
return res.status(400).json({ error: "Valid chatid and amount are required" });
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
const timestamp = getUnixTimestamp();
|
| 131 |
+
|
| 132 |
+
// Load existing amounts2
|
| 133 |
+
let amounts = JSON.parse(fs.readFileSync(AMOUNTS_FILE_2, "utf8"));
|
| 134 |
+
|
| 135 |
+
// Store the new amount
|
| 136 |
+
if (!amounts[chatId]) {
|
| 137 |
+
amounts[chatId] = [];
|
| 138 |
+
}
|
| 139 |
+
amounts[chatId].push({ amount, timestamp });
|
| 140 |
+
|
| 141 |
+
// Save to amounts2.json
|
| 142 |
+
fs.writeFileSync(AMOUNTS_FILE_2, JSON.stringify(amounts, null, 2), "utf8");
|
| 143 |
+
|
| 144 |
+
res.json({ chatId, amount, timestamp });
|
| 145 |
+
});
|
| 146 |
+
|
| 147 |
+
// API to get stored amounts for a chat ID (Version 2)
|
| 148 |
+
app.get("/get2", (req, res) => {
|
| 149 |
+
const chatId = req.query.chatid;
|
| 150 |
+
|
| 151 |
+
if (!chatId) {
|
| 152 |
+
return res.status(400).json({ error: "chatid is required" });
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// Load existing amounts2
|
| 156 |
+
let amounts = JSON.parse(fs.readFileSync(AMOUNTS_FILE_2, "utf8"));
|
| 157 |
+
|
| 158 |
+
if (!amounts[chatId]) {
|
| 159 |
+
return res.status(404).json({ error: "No amounts found for this chat ID" });
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
res.json({ chatId, amounts: amounts[chatId] });
|
| 163 |
+
});
|
| 164 |
+
|
| 165 |
// Start server
|
| 166 |
app.listen(PORT, () => {
|
| 167 |
console.log(`Server running on port ${PORT}`);
|