Anpassungen zum Thema IP Resolving
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { readFileSync } from 'fs';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { join } from 'path';
|
||||
import { CityAndStateResult, CountyResult, GeoResult } from 'src/models/main.model';
|
||||
import { Logger } from 'winston';
|
||||
import { City, CountyData, Geo, State } from '../models/server.model';
|
||||
|
||||
// const __filename = fileURLToPath(import.meta.url);
|
||||
// const __dirname = path.dirname(__filename);
|
||||
|
||||
@@ -11,7 +12,7 @@ import { City, CountyData, Geo, State } from '../models/server.model';
|
||||
export class GeoService {
|
||||
geo: Geo;
|
||||
counties: CountyData[];
|
||||
constructor() {
|
||||
constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {
|
||||
this.loadGeo();
|
||||
}
|
||||
private loadGeo(): void {
|
||||
@@ -101,6 +102,7 @@ export class GeoService {
|
||||
return this.geo.states.find(s => s.state_code === state).cities.find(c => c.name === city);
|
||||
}
|
||||
async fetchIpAndGeoLocation(ip: string): Promise<any> {
|
||||
this.logger.info(`IP:${ip}`);
|
||||
const response = await fetch(`${process.env.IP_INFO_URL}/${ip}/geo?token=${process.env.IP_INFO_TOKEN}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user