feat: Implement server configuration management API and integrate server management features in FilterManager for enhanced server handling capabilities
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 4m8s

This commit is contained in:
2025-07-14 09:54:16 +07:00
parent 43a77bc3b1
commit a42e103bba
2 changed files with 441 additions and 101 deletions
+132
View File
@@ -516,6 +516,138 @@ app.post('/api/filters/export-config', async (req, res) => {
}
});
// --- Server Configs Routes ---
// Get server configs list
app.get('/api/server-configs', async (req, res) => {
const params = {
Bucket: BUCKET_NAME,
Key: 'server-configs.json',
};
try {
const data = await s3.getObject(params).promise();
const fileContent = data.Body.toString('utf-8');
let servers = [];
try {
servers = JSON.parse(fileContent);
if (!Array.isArray(servers)) {
servers = [];
}
} catch (parseError) {
console.error('Error parsing server-configs.json:', parseError);
servers = [];
}
res.json(servers);
} catch (error) {
if (error.code === 'NoSuchKey') {
res.json([]); // Return empty array if file does not exist
} else {
console.error(error);
res.status(500).send('Error reading server configs from S3');
}
}
});
// Update server configs list
app.post('/api/server-configs', async (req, res) => {
const { servers } = req.body;
// Validate servers structure
if (!Array.isArray(servers)) {
return res.status(400).send('Servers must be an array');
}
// Validate each server has required fields
for (let i = 0; i < servers.length; i++) {
const server = servers[i];
if (!server.id || !server.name) {
return res.status(400).send(`Server at index ${i} is missing required fields`);
}
}
const params = {
Bucket: BUCKET_NAME,
Key: 'server-configs.json',
Body: JSON.stringify(servers, null, 2), // Pretty print JSON
ContentType: 'application/json',
};
try {
await s3.putObject(params).promise();
res.send('Server configs updated successfully');
} catch (error) {
console.error(error);
res.status(500).send('Error writing server configs to S3');
}
});
// Get specific server config
app.get('/api/server-configs/:serverId', async (req, res) => {
const { serverId } = req.params;
const params = {
Bucket: BUCKET_NAME,
Key: `config-${serverId}.txt`,
};
try {
const data = await s3.getObject(params).promise();
const config = data.Body.toString('utf-8');
res.json({ config });
} catch (error) {
if (error.code === 'NoSuchKey') {
res.json({ config: '// Конфигурация не найдена' });
} else {
console.error(error);
res.status(500).send('Error reading server config from S3');
}
}
});
// Save specific server config
app.post('/api/server-configs/:serverId', async (req, res) => {
const { serverId } = req.params;
const { config } = req.body;
if (!config) {
return res.status(400).send('Config is required');
}
const params = {
Bucket: BUCKET_NAME,
Key: `config-${serverId}.txt`,
Body: config,
ContentType: 'text/plain',
};
try {
await s3.putObject(params).promise();
res.send('Server config saved successfully');
} catch (error) {
console.error(error);
res.status(500).send('Error writing server config to S3');
}
});
// Delete specific server config
app.delete('/api/server-configs/:serverId', async (req, res) => {
const { serverId } = req.params;
const params = {
Bucket: BUCKET_NAME,
Key: `config-${serverId}.txt`,
};
try {
await s3.deleteObject(params).promise();
res.send('Server config deleted successfully');
} catch (error) {
console.error(error);
res.status(500).send('Error deleting server config from S3');
}
});
// The "catchall" handler: for any request that doesn't
// match one above, send back React's index.html file.
app.get('*', (req, res) => {