Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
|
@@ -19,7 +19,7 @@ const limiter = rateLimit({
|
|
| 19 |
windowMs: 60 * 1000, // 60 секунд
|
| 20 |
max: 8, // лимит каждые 60 секунд на IP
|
| 21 |
handler: function (req, res) {
|
| 22 |
-
return res.status(429).json("
|
| 23 |
},
|
| 24 |
});
|
| 25 |
|
|
@@ -29,7 +29,7 @@ app.use('/pl', limiter);
|
|
| 29 |
const start = `${process.env.start}`;
|
| 30 |
|
| 31 |
app.post('/update', async (req, res) => {
|
| 32 |
-
res.json({
|
| 33 |
});
|
| 34 |
|
| 35 |
app.post('/pl', async (req, res) => {
|
|
@@ -39,7 +39,7 @@ app.post('/pl', async (req, res) => {
|
|
| 39 |
const apiKey = req.body.api || getRandomApiKey();
|
| 40 |
|
| 41 |
if (!prompt) {
|
| 42 |
-
return res.status(400).json(
|
| 43 |
}
|
| 44 |
|
| 45 |
try {
|
|
@@ -56,23 +56,18 @@ app.post('/pl', async (req, res) => {
|
|
| 56 |
},
|
| 57 |
});
|
| 58 |
|
| 59 |
-
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 60 |
-
const content = response.data.choices.
|
| 61 |
-
|
| 62 |
-
console.info(response.data.choices.trim());
|
| 63 |
res.json({ content });
|
| 64 |
} else {
|
| 65 |
-
res.json({
|
| 66 |
}
|
| 67 |
} catch (error) {
|
| 68 |
console.error(error);
|
| 69 |
-
res.json({
|
| 70 |
}
|
| 71 |
});
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
const port = 7860;
|
| 77 |
app.listen(port, () => {
|
| 78 |
console.log(`API сервер запущен на порту ${port}`);
|
|
|
|
| 19 |
windowMs: 60 * 1000, // 60 секунд
|
| 20 |
max: 8, // лимит каждые 60 секунд на IP
|
| 21 |
handler: function (req, res) {
|
| 22 |
+
return res.status(429).json({ error: "", title: "Ожидайте", text: "Слишком много запросов. Попробуйте позже.", okb: "Ок", oklink: "", cancelable: "true" });
|
| 23 |
},
|
| 24 |
});
|
| 25 |
|
|
|
|
| 29 |
const start = `${process.env.start}`;
|
| 30 |
|
| 31 |
app.post('/update', async (req, res) => {
|
| 32 |
+
res.json({ error: "", title: "Требуется обновление", text: "Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru", okb: "Обновить", oklink: "https://t.me/yufi_ru", cancelable: "false" });
|
| 33 |
});
|
| 34 |
|
| 35 |
app.post('/pl', async (req, res) => {
|
|
|
|
| 39 |
const apiKey = req.body.api || getRandomApiKey();
|
| 40 |
|
| 41 |
if (!prompt) {
|
| 42 |
+
return res.status(400).json({ error: "", title: "Ошибка", text: "Нет запроса!", okb: "Ок", oklink: "", cancelable: "true" }); // Не удалось принять данные
|
| 43 |
}
|
| 44 |
|
| 45 |
try {
|
|
|
|
| 56 |
},
|
| 57 |
});
|
| 58 |
|
| 59 |
+
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message && response.data.choices[0].message.content) {
|
| 60 |
+
const content = response.data.choices[0].message.content;
|
|
|
|
|
|
|
| 61 |
res.json({ content });
|
| 62 |
} else {
|
| 63 |
+
res.json({ error: "", title: "Ошибка", text: "Произошла ошибка на сервере. (Ошибка прочтения)", okb: "Ок", oklink: "", cancelable: "true" });
|
| 64 |
}
|
| 65 |
} catch (error) {
|
| 66 |
console.error(error);
|
| 67 |
+
res.json({ error: "", title: "Ошибка", text: "Произошла ошибка на сервере. (Ошибка при генерации)", okb: "Ок", oklink: "", cancelable: "true" });
|
| 68 |
}
|
| 69 |
});
|
| 70 |
|
|
|
|
|
|
|
|
|
|
| 71 |
const port = 7860;
|
| 72 |
app.listen(port, () => {
|
| 73 |
console.log(`API сервер запущен на порту ${port}`);
|