From 8926f599c043bd5a4b8c86a3651ae0339ec7da9a Mon Sep 17 00:00:00 2001 From: Denis Shatskiy Date: Mon, 14 Jul 2025 09:00:56 +0700 Subject: [PATCH] feat: Add new API endpoints for managing domains and integrate DomainsNewManager in the frontend for enhanced domain management functionality --- backend/server.js | 54 +++- frontend/src/App.jsx | 5 +- frontend/src/DomainsNewManager.jsx | 428 +++++++++++++++++++++++++++++ 3 files changed, 485 insertions(+), 2 deletions(-) create mode 100644 frontend/src/DomainsNewManager.jsx diff --git a/backend/server.js b/backend/server.js index c589344..990d2ef 100644 --- a/backend/server.js +++ b/backend/server.js @@ -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 diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 15a2069..c86e861 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -22,6 +22,7 @@ import { import DataManager from './DataManager'; import ServerManager from './ServerManager'; import FilterManager from './FilterManager'; +import DomainsNewManager from './DomainsNewManager'; import './App.css'; import axios from 'axios'; import { @@ -50,6 +51,7 @@ function MainLayout() { const navItems = [ { id: 'domains', title: 'Домены', icon: IconWorld, path: '/domains' }, + { id: 'domains-new', title: 'Домены New', icon: IconWorld, path: '/domains-new' }, { id: 'asns', title: 'AS', icon: IconNetwork, path: '/asns' }, { id: 'servers', title: 'Серверы', icon: IconServer, path: '/servers' }, { id: 'filters', title: 'Фильтры', icon: IconFilter, path: '/filters' }, @@ -73,7 +75,7 @@ function MainLayout() { S3 Lists Manager