Spaces:
Sleeping
Sleeping
File size: 1,248 Bytes
abed4cc e6227e8 57f03d4 abed4cc 5d38af1 650a8e4 587da90 650a8e4 10fbdf7 5d38af1 587da90 c121514 5d38af1 c121514 650a8e4 2b60bab 650a8e4 587da90 5d38af1 650a8e4 587da90 abed4cc 5d38af1 abed4cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
app.post('/fetch-sheet', async (req, res) => {
const { key, list, page, max } = req.body;
if (!key || !list || !page || !max) {
return res.status(400).json({ error: '❌ Ошибка данных, повторите попытку.' });
}
// Экранирование значений для использования в URL
const encodedKey = encodeURIComponent(key);
const encodedList = encodeURIComponent(list);
try {
const url = `https://opensheet.elk.sh/${encodedKey}/${encodedList}`;
const response = await axios.get(url);
const data = response.data;
// Разделение данных на страницы
const startIndex = (page - 1) * max;
const endIndex = startIndex + max;
const paginatedData = data.slice(startIndex, endIndex);
res.json(paginatedData);
} catch (error) {
console.error(error);
res.status(500).json({ error: '❌ Произошла ошибка сервера при запросе данных.' });
}
});
const port = 7860;
app.listen(port, () => {
console.log(`API сервер запущен на порту ${port}`);
}); |