feat: Add new API endpoints for managing domains and integrate DomainsNewManager in the frontend for enhanced domain management functionality
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 6m24s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 6m24s
This commit is contained in:
+53
-1
@@ -126,6 +126,56 @@ app.post('/api/asns', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// --- Domains New Routes ---
|
||||
|
||||
// Get domains-new from S3
|
||||
app.get('/api/domains-new', async (req, res) => {
|
||||
const params = {
|
||||
Bucket: BUCKET_NAME,
|
||||
Key: 'domains_comunity.txt',
|
||||
};
|
||||
|
||||
try {
|
||||
const data = await s3.getObject(params).promise();
|
||||
const fileContent = data.Body.toString('utf-8');
|
||||
const domains = fileContent.split('\n').filter(line => line).map(line => {
|
||||
const parts = line.trim().split(/\s+/);
|
||||
const domain = parts[0] || '';
|
||||
const community = parts[1] || '';
|
||||
return { domain, community };
|
||||
});
|
||||
res.json(domains);
|
||||
} 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 from S3');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Update domains-new in S3
|
||||
app.post('/api/domains-new', async (req, res) => {
|
||||
const { domains } = req.body;
|
||||
const fileContent = domains.map(d => `${d.domain} ${d.community}`).join('\n');
|
||||
|
||||
const params = {
|
||||
Bucket: BUCKET_NAME,
|
||||
Key: 'domains_comunity.txt',
|
||||
Body: fileContent,
|
||||
ContentType: 'text/plain',
|
||||
};
|
||||
|
||||
try {
|
||||
await s3.putObject(params).promise();
|
||||
res.send('File updated successfully');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).send('Error writing to S3');
|
||||
}
|
||||
});
|
||||
|
||||
// --- Servers Routes (JSON format) ---
|
||||
|
||||
// Get servers from S3
|
||||
@@ -267,14 +317,16 @@ app.post('/api/filters', async (req, res) => {
|
||||
// Новый эндпоинт для получения дат последнего изменения файлов S3
|
||||
app.get('/api/s3/last-modified', async (req, res) => {
|
||||
try {
|
||||
const [domainsHead, asnsHead, serversHead, filtersHead] = await Promise.all([
|
||||
const [domainsHead, domainsNewHead, asnsHead, serversHead, filtersHead] = await Promise.all([
|
||||
s3.headObject({ Bucket: BUCKET_NAME, Key: 'domains.txt' }).promise(),
|
||||
s3.headObject({ Bucket: BUCKET_NAME, Key: 'domains_comunity.txt' }).promise(),
|
||||
s3.headObject({ Bucket: BUCKET_NAME, Key: 'asns.txt' }).promise(),
|
||||
s3.headObject({ Bucket: BUCKET_NAME, Key: 'servers.json' }).promise(),
|
||||
s3.headObject({ Bucket: BUCKET_NAME, Key: 'filters.json' }).promise()
|
||||
]);
|
||||
res.json({
|
||||
domainsLastModified: domainsHead.LastModified ? domainsHead.LastModified.toISOString() : null,
|
||||
domainsNewLastModified: domainsNewHead.LastModified ? domainsNewHead.LastModified.toISOString() : null,
|
||||
asnsLastModified: asnsHead.LastModified ? asnsHead.LastModified.toISOString() : null,
|
||||
serversLastModified: serversHead.LastModified ? serversHead.LastModified.toISOString() : null,
|
||||
filtersLastModified: filtersHead.LastModified ? filtersHead.LastModified.toISOString() : null
|
||||
|
||||
Reference in New Issue
Block a user