From 646e9be382175bb4ba4f072c03938bd5c6d34cf2 Mon Sep 17 00:00:00 2001 From: Denis Shatskiy Date: Mon, 14 Jul 2025 22:17:41 +0700 Subject: [PATCH] refactor: Update S3 file paths in server.js to use a new directory structure for better organization --- backend/server.js | 20 +++++------ example/s3/bgp_data/README.md | 46 ++++++++++++++++++++++++ example/s3/bgp_data/asns.txt | 5 +++ example/s3/bgp_data/domains.txt | 5 +++ example/s3/bgp_data/domains_comunity.txt | 5 +++ example/s3/bgp_data/ips.txt | 5 +++ 6 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 example/s3/bgp_data/README.md create mode 100644 example/s3/bgp_data/asns.txt create mode 100644 example/s3/bgp_data/domains.txt create mode 100644 example/s3/bgp_data/domains_comunity.txt create mode 100644 example/s3/bgp_data/ips.txt diff --git a/backend/server.js b/backend/server.js index 972506c..16be636 100644 --- a/backend/server.js +++ b/backend/server.js @@ -24,7 +24,7 @@ const s3 = new AWS.S3({ }); const BUCKET_NAME = process.env.S3_BUCKET_NAME; -const FILE_KEY = 'domains.txt'; +const FILE_KEY = 'bgp_data/domains.txt'; // Get domains from S3 app.get('/api/domains', async (req, res) => { @@ -82,7 +82,7 @@ app.post('/api/domains', async (req, res) => { app.get('/api/asns', async (req, res) => { const params = { Bucket: BUCKET_NAME, - Key: 'asns.txt', + Key: 'bgp_data/asns.txt', }; try { @@ -112,7 +112,7 @@ app.post('/api/asns', async (req, res) => { const params = { Bucket: BUCKET_NAME, - Key: 'asns.txt', + Key: 'bgp_data/asns.txt', Body: fileContent, ContentType: 'text/plain', }; @@ -132,7 +132,7 @@ app.post('/api/asns', async (req, res) => { app.get('/api/domains-new', async (req, res) => { const params = { Bucket: BUCKET_NAME, - Key: 'domains_comunity.txt', + Key: 'bgp_data/domains_comunity.txt', }; try { @@ -162,7 +162,7 @@ app.post('/api/domains-new', async (req, res) => { const params = { Bucket: BUCKET_NAME, - Key: 'domains_comunity.txt', + Key: 'bgp_data/domains_comunity.txt', Body: fileContent, ContentType: 'text/plain', }; @@ -182,7 +182,7 @@ app.post('/api/domains-new', async (req, res) => { app.get('/api/ip-ranges', async (req, res) => { const params = { Bucket: BUCKET_NAME, - Key: 'domains/ips.txt', + Key: 'bgp_data/ips.txt', }; try { @@ -212,7 +212,7 @@ app.post('/api/ip-ranges', async (req, res) => { const params = { Bucket: BUCKET_NAME, - Key: 'domains/ips.txt', + Key: 'bgp_data/ips.txt', Body: fileContent, ContentType: 'text/plain', }; @@ -368,9 +368,9 @@ app.post('/api/filters', async (req, res) => { app.get('/api/s3/last-modified', async (req, res) => { try { 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: 'bgp_data/domains.txt' }).promise(), + s3.headObject({ Bucket: BUCKET_NAME, Key: 'bgp_data/domains_comunity.txt' }).promise(), + s3.headObject({ Bucket: BUCKET_NAME, Key: 'bgp_data/asns.txt' }).promise(), s3.headObject({ Bucket: BUCKET_NAME, Key: 'servers.json' }).promise(), s3.headObject({ Bucket: BUCKET_NAME, Key: 'filters.json' }).promise() ]); diff --git a/example/s3/bgp_data/README.md b/example/s3/bgp_data/README.md new file mode 100644 index 0000000..b092d9f --- /dev/null +++ b/example/s3/bgp_data/README.md @@ -0,0 +1,46 @@ +# BGP Data Files + +Эта папка содержит файлы данных для BGP-маршрутизации: + +## Структура файлов + +### domains.txt +Файл с доменами и их типами (старый формат): +``` +example.com 100 +google.com 101 +facebook.com 102 +``` + +### domains_comunity.txt +Файл с доменами и их community (новый формат): +``` +example.com 100 +google.com 101 +facebook.com 102 +``` + +### asns.txt +Файл с номерами AS и их community: +``` +12345 112 +4545 113 +6789 114 +``` + +### ips.txt +Файл с IP-диапазонами и их community: +``` +192.168.1.0/24 100 +10.0.0.0/8 101 +172.16.0.0/12 102 +``` + +## Формат файлов + +Все файлы имеют текстовый формат с разделителем пробел между значениями. +Каждая строка содержит два поля: +- Первое поле: домен/AS/IP-диапазон +- Второе поле: community/тип + +Пустые строки игнорируются при обработке. \ No newline at end of file diff --git a/example/s3/bgp_data/asns.txt b/example/s3/bgp_data/asns.txt new file mode 100644 index 0000000..711c596 --- /dev/null +++ b/example/s3/bgp_data/asns.txt @@ -0,0 +1,5 @@ +12345 112 +4545 113 +6789 114 +1011 115 +1213 116 \ No newline at end of file diff --git a/example/s3/bgp_data/domains.txt b/example/s3/bgp_data/domains.txt new file mode 100644 index 0000000..7ef6cd7 --- /dev/null +++ b/example/s3/bgp_data/domains.txt @@ -0,0 +1,5 @@ +example.com 100 +google.com 101 +facebook.com 102 +youtube.com 103 +github.com 104 \ No newline at end of file diff --git a/example/s3/bgp_data/domains_comunity.txt b/example/s3/bgp_data/domains_comunity.txt new file mode 100644 index 0000000..7ef6cd7 --- /dev/null +++ b/example/s3/bgp_data/domains_comunity.txt @@ -0,0 +1,5 @@ +example.com 100 +google.com 101 +facebook.com 102 +youtube.com 103 +github.com 104 \ No newline at end of file diff --git a/example/s3/bgp_data/ips.txt b/example/s3/bgp_data/ips.txt new file mode 100644 index 0000000..ad78411 --- /dev/null +++ b/example/s3/bgp_data/ips.txt @@ -0,0 +1,5 @@ +192.168.1.0/24 100 +10.0.0.0/8 101 +172.16.0.0/12 102 +8.8.8.0/24 103 +1.1.1.0/24 104 \ No newline at end of file