feat: Implement simple filters management in FilterManager with API integration for fetching, adding, and deleting filters, enhancing user experience and functionality
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m46s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m46s
This commit is contained in:
@@ -785,6 +785,74 @@ app.post('/api/server-filters/:serverId', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// --- Simple Filters Routes ---
|
||||
|
||||
// Get simple filters
|
||||
app.get('/api/simple-filters', async (req, res) => {
|
||||
const params = {
|
||||
Bucket: BUCKET_NAME,
|
||||
Key: 'simple-filters.json',
|
||||
};
|
||||
|
||||
try {
|
||||
const data = await s3.getObject(params).promise();
|
||||
const fileContent = data.Body.toString('utf-8');
|
||||
let filters = [];
|
||||
|
||||
try {
|
||||
filters = JSON.parse(fileContent);
|
||||
if (!Array.isArray(filters)) {
|
||||
filters = [];
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('Error parsing simple filters:', parseError);
|
||||
filters = [];
|
||||
}
|
||||
|
||||
res.json(filters);
|
||||
} 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 simple filters from S3');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Update simple filters
|
||||
app.post('/api/simple-filters', async (req, res) => {
|
||||
const { filters } = req.body;
|
||||
|
||||
// Validate filters structure
|
||||
if (!Array.isArray(filters)) {
|
||||
return res.status(400).send('Filters must be an array');
|
||||
}
|
||||
|
||||
// Validate each filter has required fields
|
||||
for (let i = 0; i < filters.length; i++) {
|
||||
const filter = filters[i];
|
||||
if (!filter.community || !filter.gateway) {
|
||||
return res.status(400).send(`Filter at index ${i} is missing required fields`);
|
||||
}
|
||||
}
|
||||
|
||||
const params = {
|
||||
Bucket: BUCKET_NAME,
|
||||
Key: 'simple-filters.json',
|
||||
Body: JSON.stringify(filters, null, 2), // Pretty print JSON
|
||||
ContentType: 'application/json',
|
||||
};
|
||||
|
||||
try {
|
||||
await s3.putObject(params).promise();
|
||||
res.send('Simple filters updated successfully');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).send('Error writing simple filters to S3');
|
||||
}
|
||||
});
|
||||
|
||||
// The "catchall" handler: for any request that doesn't
|
||||
// match one above, send back React's index.html file.
|
||||
app.get('*', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user