Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const rateLimit = require('express-rate-limit');
|
| 3 |
const axios = require('axios');
|
| 4 |
-
const winston = require('winston');
|
| 5 |
-
require('winston-daily-rotate-file');
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
app.use(express.json());
|
|
@@ -17,28 +15,6 @@ function getRandomApiKey() {
|
|
| 17 |
return openai_keys[randomIndex];
|
| 18 |
}
|
| 19 |
|
| 20 |
-
// Настройка логирования с помощью winston
|
| 21 |
-
const transport = new winston.transports.DailyRotateFile({
|
| 22 |
-
filename: 'application-%DATE%.log',
|
| 23 |
-
datePattern: 'YYYY-MM-DD',
|
| 24 |
-
maxSize: '20m',
|
| 25 |
-
maxFiles: '5d', // хранить файлы не более 5 дней
|
| 26 |
-
});
|
| 27 |
-
|
| 28 |
-
const logger = winston.createLogger({
|
| 29 |
-
level: 'info',
|
| 30 |
-
format: winston.format.combine(
|
| 31 |
-
winston.format.timestamp(),
|
| 32 |
-
winston.format.printf(({ timestamp, level, message }) => {
|
| 33 |
-
return `${timestamp} [${level}]: ${message}`;
|
| 34 |
-
})
|
| 35 |
-
),
|
| 36 |
-
transports: [
|
| 37 |
-
transport,
|
| 38 |
-
new winston.transports.Console(), // Для вывода в консоль
|
| 39 |
-
],
|
| 40 |
-
});
|
| 41 |
-
|
| 42 |
const limiter = rateLimit({
|
| 43 |
windowMs: 5 * 1000, // 5 секунд
|
| 44 |
max: 1, // лимит каждые 5 секунд на IP
|
|
@@ -54,14 +30,12 @@ app.use('/crebeta', limiter);
|
|
| 54 |
const start = `${process.env.start}`;
|
| 55 |
|
| 56 |
app.post('/cr', async (req, res) => {
|
| 57 |
-
logger.info(`/cr endpoint accessed`);
|
| 58 |
res.json({ content: `{"whate":"🪨", "howe":"ОБНОВИТЕСЬ", "text":"Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru", "succ":"победа", "what":"Версию", "how":"Обновите", "howl":"@yufi_ru"}` });
|
| 59 |
});
|
| 60 |
|
| 61 |
app.post('/pl', async (req, res) => {
|
| 62 |
const prompt = req.body.prompt;
|
| 63 |
const apiKey = req.body.api || getRandomApiKey();
|
| 64 |
-
logger.info(`/pl endpoint accessed with prompt: ${prompt}`);
|
| 65 |
|
| 66 |
if (!prompt) {
|
| 67 |
return res.status(400).json("wait"); // Не удалось принять данные
|
|
@@ -82,25 +56,23 @@ app.post('/pl', async (req, res) => {
|
|
| 82 |
|
| 83 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 84 |
const content = response.data.choices[0].message.content.trim();
|
| 85 |
-
|
| 86 |
res.json({ content });
|
| 87 |
} else {
|
| 88 |
-
|
| 89 |
-
res.status(500).json({ content: 'errora' });
|
| 90 |
}
|
| 91 |
} catch (error) {
|
| 92 |
-
|
| 93 |
-
res.status(500).json({ content: 'errorb' });
|
| 94 |
}
|
| 95 |
});
|
| 96 |
|
| 97 |
app.post('/cre', async (req, res) => {
|
| 98 |
const prompt = req.body.prompt;
|
| 99 |
const apiKey = req.body.api || getRandomApiKey();
|
| 100 |
-
logger.info(`/cre endpoint accessed with prompt: ${prompt}`);
|
| 101 |
|
| 102 |
if (!prompt) {
|
| 103 |
-
return res.status(400).json("wait");
|
| 104 |
}
|
| 105 |
|
| 106 |
try {
|
|
@@ -118,25 +90,23 @@ app.post('/cre', async (req, res) => {
|
|
| 118 |
|
| 119 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 120 |
const content = response.data.choices[0].message.content.trim();
|
| 121 |
-
|
| 122 |
res.json({ content });
|
| 123 |
} else {
|
| 124 |
-
|
| 125 |
-
res.status(500).json({ content: 'errora' });
|
| 126 |
}
|
| 127 |
} catch (error) {
|
| 128 |
-
|
| 129 |
-
res.status(500).json({ content: 'errorb' });
|
| 130 |
}
|
| 131 |
});
|
| 132 |
|
| 133 |
app.post('/crebeta', async (req, res) => {
|
| 134 |
const prompt = req.body.prompt;
|
| 135 |
const apiKey = req.body.api || getRandomApiKey();
|
| 136 |
-
logger.info(`/crebeta endpoint accessed with prompt: ${prompt}`);
|
| 137 |
|
| 138 |
if (!prompt) {
|
| 139 |
-
return res.status(400).json("wait");
|
| 140 |
}
|
| 141 |
|
| 142 |
try {
|
|
@@ -154,19 +124,18 @@ app.post('/crebeta', async (req, res) => {
|
|
| 154 |
|
| 155 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 156 |
const content = response.data.choices[0].message.content.trim();
|
| 157 |
-
|
| 158 |
res.json({ content });
|
| 159 |
} else {
|
| 160 |
-
|
| 161 |
-
res.status(500).json({ content: 'errora' });
|
| 162 |
}
|
| 163 |
} catch (error) {
|
| 164 |
-
|
| 165 |
-
res.status(500).json({ content: 'errorb' });
|
| 166 |
}
|
| 167 |
});
|
| 168 |
|
| 169 |
const port = 7860;
|
| 170 |
app.listen(port, () => {
|
| 171 |
-
|
| 172 |
});
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const rateLimit = require('express-rate-limit');
|
| 3 |
const axios = require('axios');
|
|
|
|
|
|
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
app.use(express.json());
|
|
|
|
| 15 |
return openai_keys[randomIndex];
|
| 16 |
}
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
const limiter = rateLimit({
|
| 19 |
windowMs: 5 * 1000, // 5 секунд
|
| 20 |
max: 1, // лимит каждые 5 секунд на IP
|
|
|
|
| 30 |
const start = `${process.env.start}`;
|
| 31 |
|
| 32 |
app.post('/cr', async (req, res) => {
|
|
|
|
| 33 |
res.json({ content: `{"whate":"🪨", "howe":"ОБНОВИТЕСЬ", "text":"Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru", "succ":"победа", "what":"Версию", "how":"Обновите", "howl":"@yufi_ru"}` });
|
| 34 |
});
|
| 35 |
|
| 36 |
app.post('/pl', async (req, res) => {
|
| 37 |
const prompt = req.body.prompt;
|
| 38 |
const apiKey = req.body.api || getRandomApiKey();
|
|
|
|
| 39 |
|
| 40 |
if (!prompt) {
|
| 41 |
return res.status(400).json("wait"); // Не удалось принять данные
|
|
|
|
| 56 |
|
| 57 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 58 |
const content = response.data.choices[0].message.content.trim();
|
| 59 |
+
console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
| 60 |
res.json({ content });
|
| 61 |
} else {
|
| 62 |
+
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
|
|
|
|
| 63 |
}
|
| 64 |
} catch (error) {
|
| 65 |
+
console.error(error);
|
| 66 |
+
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
|
| 67 |
}
|
| 68 |
});
|
| 69 |
|
| 70 |
app.post('/cre', async (req, res) => {
|
| 71 |
const prompt = req.body.prompt;
|
| 72 |
const apiKey = req.body.api || getRandomApiKey();
|
|
|
|
| 73 |
|
| 74 |
if (!prompt) {
|
| 75 |
+
return res.status(400).json("wait"); // Не удалось принять данные
|
| 76 |
}
|
| 77 |
|
| 78 |
try {
|
|
|
|
| 90 |
|
| 91 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 92 |
const content = response.data.choices[0].message.content.trim();
|
| 93 |
+
console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
| 94 |
res.json({ content });
|
| 95 |
} else {
|
| 96 |
+
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
|
|
|
|
| 97 |
}
|
| 98 |
} catch (error) {
|
| 99 |
+
console.error(error);
|
| 100 |
+
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
|
| 101 |
}
|
| 102 |
});
|
| 103 |
|
| 104 |
app.post('/crebeta', async (req, res) => {
|
| 105 |
const prompt = req.body.prompt;
|
| 106 |
const apiKey = req.body.api || getRandomApiKey();
|
|
|
|
| 107 |
|
| 108 |
if (!prompt) {
|
| 109 |
+
return res.status(400).json("wait"); // Не удалось принять данные
|
| 110 |
}
|
| 111 |
|
| 112 |
try {
|
|
|
|
| 124 |
|
| 125 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
| 126 |
const content = response.data.choices[0].message.content.trim();
|
| 127 |
+
console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
| 128 |
res.json({ content });
|
| 129 |
} else {
|
| 130 |
+
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
|
|
|
|
| 131 |
}
|
| 132 |
} catch (error) {
|
| 133 |
+
console.error(error);
|
| 134 |
+
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
|
| 135 |
}
|
| 136 |
});
|
| 137 |
|
| 138 |
const port = 7860;
|
| 139 |
app.listen(port, () => {
|
| 140 |
+
console.log(`API сервер запущен на порту ${port}`);
|
| 141 |
});
|