Skip to content

Commit c90baf8

Browse files
authored
Merge pull request #46 from artemploxoyy/update-v1
сохранение настроек прокси при перезагрузке плагинов, исправление
2 parents 721638d + 22c8f7d commit c90baf8

4 files changed

Lines changed: 101 additions & 119 deletions

File tree

backend/src/api/routes/bots.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,24 @@ router.put('/:botId/users/:userId', authorize('management:edit'), async (req, re
11891189
router.post('/start-all', authorize('bot:start_stop'), async (req, res) => {
11901190
try {
11911191
console.log('[API] Получен запрос на запуск всех ботов.');
1192-
const allBots = await prisma.bot.findMany({ include: { server: true, proxy: true } });
1192+
1193+
// Определяем фильтр доступа по ботам для пользователя
1194+
let whereFilter = {};
1195+
if (req.user && typeof req.user.userId === 'number') {
1196+
const panelUser = await prisma.panelUser.findUnique({
1197+
where: { id: req.user.userId },
1198+
include: { botAccess: { select: { botId: true } } }
1199+
});
1200+
if (panelUser && panelUser.allBots === false) {
1201+
const allowedIds = panelUser.botAccess.map(a => a.botId);
1202+
whereFilter = { id: { in: allowedIds.length ? allowedIds : [-1] } };
1203+
}
1204+
}
1205+
1206+
const allBots = await prisma.bot.findMany({
1207+
where: whereFilter,
1208+
include: { server: true, proxy: true }
1209+
});
11931210
let startedCount = 0;
11941211
for (const botConfig of allBots) {
11951212
if (!botManager.bots.has(botConfig.id)) {
@@ -1204,12 +1221,29 @@ router.post('/start-all', authorize('bot:start_stop'), async (req, res) => {
12041221
}
12051222
});
12061223

1207-
router.post('/stop-all', authorize('bot:start_stop'), (req, res) => {
1224+
router.post('/stop-all', authorize('bot:start_stop'), async (req, res) => {
12081225
try {
12091226
console.log('[API] Получен запрос на остановку всех ботов.');
1227+
1228+
// Определяем фильтр доступа по ботам для пользователя
1229+
let allowedBotIds = null;
1230+
if (req.user && typeof req.user.userId === 'number') {
1231+
const panelUser = await prisma.panelUser.findUnique({
1232+
where: { id: req.user.userId },
1233+
include: { botAccess: { select: { botId: true } } }
1234+
});
1235+
if (panelUser && panelUser.allBots === false) {
1236+
allowedBotIds = new Set(panelUser.botAccess.map(a => a.botId));
1237+
}
1238+
}
1239+
12101240
const botIds = Array.from(botManager.bots.keys());
12111241
let stoppedCount = 0;
12121242
for (const botId of botIds) {
1243+
// Если у пользователя есть ограничения, проверяем доступ
1244+
if (allowedBotIds !== null && !allowedBotIds.has(botId)) {
1245+
continue;
1246+
}
12131247
botManager.stopBot(botId);
12141248
stoppedCount++;
12151249
}

backend/src/core/BotProcess.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async function fetchNewConfig(botId, prisma) {
6868
where: { id: botId },
6969
include: {
7070
server: true,
71+
proxy: true,
7172
installedPlugins: {
7273
where: { isEnabled: true }
7374
},
@@ -1356,6 +1357,8 @@ process.on('message', async (message) => {
13561357
sendLog('[System] Получена команда на перезагрузку плагинов...');
13571358
const newConfig = await fetchNewConfig(bot.config.id, prisma);
13581359
if (newConfig) {
1360+
// Обновляем конфигурацию бота, сохраняя все поля включая прокси
1361+
bot.config = { ...bot.config, ...newConfig };
13591362
bot.config.plugins = newConfig.installedPlugins;
13601363
bot.commands.clear();
13611364
await loadCommands(bot, newConfig.commands);

frontend/src/components/InstalledPluginsView.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function InstalledPluginCard({ plugin, botId, updateInfo, onToggle, onDelete, on
179179
{hasSettings && onOpenSettings && (
180180
<Tooltip>
181181
<TooltipTrigger asChild>
182-
<Button variant="ghost" size="icon" className="h-8 w-8" disabled={!plugin.isEnabled} onClick={() => onOpenSettings(plugin)}>
182+
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => onOpenSettings(plugin)}>
183183
<Settings className="h-4 w-4" />
184184
</Button>
185185
</TooltipTrigger>
@@ -401,7 +401,7 @@ function InstalledPluginCard({ plugin, botId, updateInfo, onToggle, onDelete, on
401401
{hasSettings && onOpenSettings && (
402402
<Tooltip>
403403
<TooltipTrigger asChild>
404-
<Button variant="outline" size="sm" disabled={!plugin.isEnabled} onClick={() => onOpenSettings(plugin)}>
404+
<Button variant="outline" size="sm" onClick={() => onOpenSettings(plugin)}>
405405
<Settings className="h-4 w-4" />
406406
</Button>
407407
</TooltipTrigger>

0 commit comments

Comments
 (0)