mirror of
https://github.com/zoriya/flood.git
synced 2025-12-05 23:06:20 +00:00
build: embed mmdb as pure js data (#782)
This commit is contained in:
1
server/geoip/.gitignore
vendored
Normal file
1
server/geoip/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
GeoLite2-Country.mmdb
|
||||
9
server/geoip/data.ts
Normal file
9
server/geoip/data.ts
Normal file
File diff suppressed because one or more lines are too long
3
server/geoip/readme.md
Normal file
3
server/geoip/readme.md
Normal file
@@ -0,0 +1,3 @@
|
||||
download `GeoLite2-Country.mmdb` from maxmind and put it here.
|
||||
|
||||
Then run `node ./scripts/update-mmdb.mjs` to update `data.ts`
|
||||
@@ -1,4 +1,3 @@
|
||||
import geoip from 'geoip-country';
|
||||
import path from 'path';
|
||||
|
||||
import type {
|
||||
@@ -26,6 +25,7 @@ import type {TransferSummary} from '@shared/types/TransferData';
|
||||
import type {TransmissionConnectionSettings} from '@shared/schema/ClientConnectionSettings';
|
||||
import type {SetClientSettingsOptions} from '@shared/types/api/client';
|
||||
|
||||
import * as geoip from '../geoip';
|
||||
import ClientGatewayService from '../clientGatewayService';
|
||||
import ClientRequestManager from './clientRequestManager';
|
||||
import {fetchUrls} from '../../util/fetchUtil';
|
||||
@@ -195,7 +195,7 @@ class TransmissionClientGatewayService extends ClientGatewayService {
|
||||
.filter((peer) => peer.isDownloadingFrom || peer.isUploadingTo)
|
||||
.map((peer) => ({
|
||||
address: peer.address,
|
||||
country: geoip.lookup(peer.address)?.country || '',
|
||||
country: geoip.lookup(peer.address),
|
||||
clientVersion: peer.clientName,
|
||||
completedPercent: peer.progress * 100,
|
||||
downloadRate: peer.rateToClient,
|
||||
|
||||
13
server/services/geoip.ts
Normal file
13
server/services/geoip.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {Reader} from '@maxmind/geoip2-node';
|
||||
|
||||
import * as data from '../geoip/data';
|
||||
|
||||
const r = Reader.openBuffer(data.data);
|
||||
|
||||
export function lookup(s: string): string {
|
||||
try {
|
||||
return r.country(s)?.country?.isoCode ?? '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import fs from 'fs';
|
||||
import geoip from 'geoip-country';
|
||||
import {move} from 'fs-extra';
|
||||
import path from 'path';
|
||||
import sanitize from 'sanitize-filename';
|
||||
@@ -31,6 +30,7 @@ import type {TorrentTracker} from '@shared/types/TorrentTracker';
|
||||
import type {TransferSummary} from '@shared/types/TransferData';
|
||||
import type {SetClientSettingsOptions} from '@shared/types/api/client';
|
||||
|
||||
import * as geoip from '../geoip';
|
||||
import {isAllowedPath, sanitizePath} from '../../util/fileUtil';
|
||||
import ClientGatewayService from '../clientGatewayService';
|
||||
import ClientRequestManager from './clientRequestManager';
|
||||
@@ -262,7 +262,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
|
||||
processedResponses.map(async (processedResponse) => {
|
||||
return {
|
||||
...processedResponse,
|
||||
country: geoip.lookup(processedResponse.address)?.country || '',
|
||||
country: geoip.lookup(processedResponse.address),
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user