From 86cc444bbfa96d9b96d79bb2753c97d0395fbb75 Mon Sep 17 00:00:00 2001 From: kongmoumou Date: Tue, 22 Oct 2024 21:10:11 +0800 Subject: [PATCH 1/3] chore: add geoip-lite as dev dependencies --- package-lock.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 77 insertions(+) diff --git a/package-lock.json b/package-lock.json index 4079e222..db2753f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,6 +68,7 @@ "firebase-admin": "^12.0.0", "fluent-ffmpeg": "^2.1.2", "geo-tz": "^7.0.1", + "geoip-lite": "^1.4.10", "graphql": "^14.4.2", "highlights": "^3.1.6", "hot-shots": "^6.3.0", @@ -13936,6 +13937,46 @@ "typedarray": "^0.0.6" } }, + "node_modules/geoip-lite": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/geoip-lite/-/geoip-lite-1.4.10.tgz", + "integrity": "sha512-4N69uhpS3KFd97m00wiFEefwa+L+HT5xZbzPhwu+sDawStg6UN/dPwWtUfkQuZkGIY1Cj7wDVp80IsqNtGMi2w==", + "dev": true, + "dependencies": { + "async": "2.1 - 2.6.4", + "chalk": "4.1 - 4.1.2", + "iconv-lite": "0.4.13 - 0.6.3", + "ip-address": "5.8.9 - 5.9.4", + "lazy": "1.0.11", + "rimraf": "2.5.2 - 2.7.1", + "yauzl": "2.9.2 - 2.10.0" + }, + "engines": { + "node": ">=10.3.0" + } + }, + "node_modules/geoip-lite/node_modules/async": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "dev": true, + "dependencies": { + "lodash": "^4.17.14" + } + }, + "node_modules/geoip-lite/node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, "node_modules/get-assigned-identifiers": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-assigned-identifiers/-/get-assigned-identifiers-1.2.0.tgz", @@ -15973,6 +16014,32 @@ "url": "https://opencollective.com/ioredis" } }, + "node_modules/ip-address": { + "version": "5.9.4", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-5.9.4.tgz", + "integrity": "sha512-dHkI3/YNJq4b/qQaz+c8LuarD3pY24JqZWfjB8aZx1gtpc2MDILu9L9jpZe1sHpzo/yWFweQVn+U//FhazUxmw==", + "dev": true, + "dependencies": { + "jsbn": "1.1.0", + "lodash": "^4.17.15", + "sprintf-js": "1.1.2" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/ip-address/node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "dev": true + }, + "node_modules/ip-address/node_modules/sprintf-js": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", + "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==", + "dev": true + }, "node_modules/ip-regex": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", @@ -18529,6 +18596,15 @@ "node": ">=4" } }, + "node_modules/lazy": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/lazy/-/lazy-1.0.11.tgz", + "integrity": "sha512-Y+CjUfLmIpoUCCRl0ub4smrYtGGr5AOa2AKOaWelGHOGz33X/Y/KizefGqbkwfz44+cnq/+9habclf8vOmu2LA==", + "dev": true, + "engines": { + "node": ">=0.2.0" + } + }, "node_modules/lazy-cache": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-2.0.2.tgz", diff --git a/package.json b/package.json index 0692c94b..37e45d26 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "firebase-admin": "^12.0.0", "fluent-ffmpeg": "^2.1.2", "geo-tz": "^7.0.1", + "geoip-lite": "^1.4.10", "graphql": "^14.4.2", "highlights": "^3.1.6", "hot-shots": "^6.3.0", From 344903447700ee54224e7c4bb1704693b23c96d2 Mon Sep 17 00:00:00 2001 From: kongmoumou Date: Tue, 22 Oct 2024 21:10:38 +0800 Subject: [PATCH 2/3] test: add geoip-lite test --- test/integration/geoip-lite.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/integration/geoip-lite.js diff --git a/test/integration/geoip-lite.js b/test/integration/geoip-lite.js new file mode 100644 index 00000000..6f4cdfc1 --- /dev/null +++ b/test/integration/geoip-lite.js @@ -0,0 +1,4 @@ +const geoip = require('geoip-lite'); + +const ip = "207.97.227.239"; +const geo = geoip.lookup(ip); \ No newline at end of file From f4593ed15422b79fd88527fc7588a4ef71cd9569 Mon Sep 17 00:00:00 2001 From: kongmoumou Date: Tue, 22 Oct 2024 21:11:58 +0800 Subject: [PATCH 3/3] feat: add special case handle geoip-lite --- src/utils/special-cases.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils/special-cases.ts b/src/utils/special-cases.ts index 4d04c793..db123896 100644 --- a/src/utils/special-cases.ts +++ b/src/utils/special-cases.ts @@ -333,6 +333,15 @@ const specialCases: Record void> = { emitDependency(resolve(dirname(id), 'bin/pixelmatch')); } }, + 'geoip-lite'({ id, emitAsset }) { + if (id.endsWith('geoip-lite/lib/geoip.js')) { + emitAsset(resolve(dirname(id), '../data/geoip-city.dat')); + emitAsset(resolve(dirname(id), '../data/geoip-city6.dat')); + emitAsset(resolve(dirname(id), '../data/geoip-city-names.dat')); + emitAsset(resolve(dirname(id), '../data/geoip-country.dat')); + emitAsset(resolve(dirname(id), '../data/geoip-country6.dat')); + } + }, }; interface SpecialCaseOpts {