Skip to content

Commit 1e0bcd4

Browse files
committed
Add section separators to updatedb.js for better readability
Added clear visual section separators to tools/updatedb.js (608 lines): Sections added: - GeoIP Database Updater (header) - Dependencies - Configuration - Utility Functions (mkdir, tryFixingLine, CSVtoArray) - HTTP Configuration (getHTTPOptions) - Database Download Functions (check, fetch, extract) - Data Processing Functions (processCountryData, processCityData, processCityDataNames) - Main Processing Dispatcher (processData) - Checksum Management (updateChecksum) - Main Execution Flow Benefits: - Easy navigation through 600+ lines of code - Clear separation of concerns - Better code maintainability - Improved developer experience All 94 tests pass. ESLint clean.
1 parent 351b6f7 commit 1e0bcd4

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tools/updatedb.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
// Fetches and converts MaxMind lite databases
1+
// ============================================================================
2+
// GeoIP Database Updater
3+
// Fetches and converts MaxMind GeoLite2 databases
4+
// ============================================================================
25

36
'use strict';
47

8+
// ============================================================================
9+
// Dependencies
10+
// ============================================================================
11+
512
const { name, version } = require('../package.json');
613
const UserAgent = `Mozilla/5.0 (compatible; ${name}/${version}; +https://github.com/sefinek/geoip-lite2)`;
714

@@ -19,6 +26,10 @@ const AdmZip = require('adm-zip');
1926
const utils = require('../lib/utils.js');
2027
const { Address6, Address4 } = require('ip-address');
2128

29+
// ============================================================================
30+
// Configuration
31+
// ============================================================================
32+
2233
const args = process.argv.slice(2);
2334
let license_key = args.find(arg => arg.match(/^license_key=[a-zA-Z0-9]+/) !== null);
2435
if (typeof license_key === 'undefined' && typeof process.env.LICENSE_KEY !== 'undefined') {
@@ -67,6 +78,10 @@ const databases = [{
6778
dest: ['geoip-city-names.dat', 'geoip-city.dat', 'geoip-city6.dat'],
6879
}];
6980

81+
// ============================================================================
82+
// Utility Functions
83+
// ============================================================================
84+
7085
function mkdir(dirName) {
7186
const dir = path.dirname(dirName);
7287
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
@@ -118,6 +133,10 @@ function CSVtoArray(text) {
118133
return a;
119134
}
120135

136+
// ============================================================================
137+
// HTTP Configuration
138+
// ============================================================================
139+
121140
function getHTTPOptions(downloadUrl) {
122141
const parsedUrl = new URL(downloadUrl);
123142
const options = {
@@ -140,6 +159,10 @@ function getHTTPOptions(downloadUrl) {
140159
return options;
141160
}
142161

162+
// ============================================================================
163+
// Database Download Functions
164+
// ============================================================================
165+
143166
function check(database, cb) {
144167
if (args.indexOf('force') !== -1) {
145168
// We are forcing database upgrade,
@@ -292,6 +315,10 @@ function processLookupCountry(src, cb) {
292315
});
293316
}
294317

318+
// ============================================================================
319+
// Data Processing Functions
320+
// ============================================================================
321+
295322
async function processCountryData(src, dest) {
296323
let lines = 0;
297324
const dataFile = path.join(dataPath, dest);
@@ -538,6 +565,10 @@ function processCityDataNames(src, dest, cb) {
538565
rl.on('close', cb);
539566
}
540567

568+
// ============================================================================
569+
// Main Processing Dispatcher
570+
// ============================================================================
571+
541572
function processData(database, cb) {
542573
if (database.skip) return cb(null, database);
543574

@@ -573,6 +604,10 @@ function processData(database, cb) {
573604
}
574605
}
575606

607+
// ============================================================================
608+
// Checksum Management
609+
// ============================================================================
610+
576611
function updateChecksum(database, cb) {
577612
if (database.skip || !database.checkValue) return cb(); // Don't need to update checksums because it was not fetched or did not change
578613

@@ -582,6 +617,10 @@ function updateChecksum(database, cb) {
582617
});
583618
}
584619

620+
// ============================================================================
621+
// Main Execution Flow
622+
// ============================================================================
623+
585624
if (!license_key) {
586625
console.error('ERROR: Missing license_key');
587626
process.exit(1);

0 commit comments

Comments
 (0)