Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
|
@@ -88,6 +88,36 @@ app.post('/random', async (req, res) => {
|
|
| 88 |
}
|
| 89 |
});
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
const port = 7860;
|
| 92 |
app.listen(port, () => {
|
| 93 |
console.log(`API сервер запущен на порту ${port}`);
|
|
|
|
| 88 |
}
|
| 89 |
});
|
| 90 |
|
| 91 |
+
app.post('/info', async (req, res) => {
|
| 92 |
+
const { key, list, max } = req.body;
|
| 93 |
+
|
| 94 |
+
if (!key || !list) {
|
| 95 |
+
return res.status(400).json({ error: '❌ Ошибка данных, повторите попытку.' });
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
const encodedKey = encodeURIComponent(key);
|
| 99 |
+
const encodedList = encodeURIComponent(list);
|
| 100 |
+
|
| 101 |
+
try {
|
| 102 |
+
const url = `https://opensheet.elk.sh/${encodedKey}/${encodedList}`;
|
| 103 |
+
const response = await axios.get(url);
|
| 104 |
+
const data = response.data;
|
| 105 |
+
const maxPages = data.length;
|
| 106 |
+
|
| 107 |
+
const info = { max_pages: maxPages };
|
| 108 |
+
|
| 109 |
+
if (max) {
|
| 110 |
+
const pages = Math.ceil(maxPages / max);
|
| 111 |
+
info.pages = pages;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
res.json(info);
|
| 115 |
+
} catch (error) {
|
| 116 |
+
console.error(error);
|
| 117 |
+
res.status(500).json({ error: '❌ Произошла ошибка сервера при получении информации.' });
|
| 118 |
+
}
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
const port = 7860;
|
| 122 |
app.listen(port, () => {
|
| 123 |
console.log(`API сервер запущен на порту ${port}`);
|