Spaces:
Build error
Build error
fix: remove ip based query filling for serper
Browse files
src/services/serper-search.ts
CHANGED
|
@@ -2,9 +2,8 @@ import { AsyncService, AutoCastable, DownstreamServiceFailureError, Prop, RPC_CA
|
|
| 2 |
import { singleton } from 'tsyringe';
|
| 3 |
import { GlobalLogger } from './logger';
|
| 4 |
import { SecretExposer } from '../shared/services/secrets';
|
| 5 |
-
import { GEOIP_SUPPORTED_LANGUAGES, GeoIPService } from './geoip';
|
| 6 |
import { AsyncLocalContext } from './async-context';
|
| 7 |
-
import { SerperBingHTTP, SerperGoogleHTTP, SerperImageSearchResponse, SerperNewsSearchResponse, SerperSearchQueryParams, SerperWebSearchResponse
|
| 8 |
import { BlackHoleDetector } from './blackhole-detector';
|
| 9 |
import { Context } from './registry';
|
| 10 |
import { ServiceBadAttemptError } from '../shared';
|
|
@@ -20,7 +19,6 @@ export class SerperSearchService extends AsyncService {
|
|
| 20 |
constructor(
|
| 21 |
protected globalLogger: GlobalLogger,
|
| 22 |
protected secretExposer: SecretExposer,
|
| 23 |
-
protected geoipControl: GeoIPService,
|
| 24 |
protected threadLocal: AsyncLocalContext,
|
| 25 |
protected blackHoleDetector: BlackHoleDetector,
|
| 26 |
) {
|
|
@@ -49,30 +47,6 @@ export class SerperSearchService extends AsyncService {
|
|
| 49 |
doSearch(variant: 'images', query: SerperSearchQueryParams): Promise<SerperImageSearchResponse>;
|
| 50 |
doSearch(variant: 'news', query: SerperSearchQueryParams): Promise<SerperNewsSearchResponse>;
|
| 51 |
async doSearch(variant: 'web' | 'images' | 'news', query: SerperSearchQueryParams) {
|
| 52 |
-
const ip = this.threadLocal.get('ip');
|
| 53 |
-
if (ip) {
|
| 54 |
-
const geoip = await this.geoipControl.lookupCity(ip, GEOIP_SUPPORTED_LANGUAGES.EN);
|
| 55 |
-
const locationChunks = [];
|
| 56 |
-
if (geoip?.city) {
|
| 57 |
-
locationChunks.push(geoip.city);
|
| 58 |
-
}
|
| 59 |
-
if (geoip?.subdivisions?.length) {
|
| 60 |
-
for (const x of geoip.subdivisions) {
|
| 61 |
-
locationChunks.push(x.name);
|
| 62 |
-
}
|
| 63 |
-
}
|
| 64 |
-
if (geoip?.country) {
|
| 65 |
-
const code = geoip.country.code?.toLowerCase();
|
| 66 |
-
if (code && code.toUpperCase() in WORLD_COUNTRIES) {
|
| 67 |
-
query.gl ??= code;
|
| 68 |
-
}
|
| 69 |
-
locationChunks.push(geoip.country.name);
|
| 70 |
-
}
|
| 71 |
-
if (locationChunks.length) {
|
| 72 |
-
query.location ??= locationChunks.join(', ');
|
| 73 |
-
}
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
const clientIt = this.iterClient();
|
| 77 |
let client = clientIt.next().value;
|
| 78 |
if (!client) {
|
|
|
|
| 2 |
import { singleton } from 'tsyringe';
|
| 3 |
import { GlobalLogger } from './logger';
|
| 4 |
import { SecretExposer } from '../shared/services/secrets';
|
|
|
|
| 5 |
import { AsyncLocalContext } from './async-context';
|
| 6 |
+
import { SerperBingHTTP, SerperGoogleHTTP, SerperImageSearchResponse, SerperNewsSearchResponse, SerperSearchQueryParams, SerperWebSearchResponse } from '../shared/3rd-party/serper-search';
|
| 7 |
import { BlackHoleDetector } from './blackhole-detector';
|
| 8 |
import { Context } from './registry';
|
| 9 |
import { ServiceBadAttemptError } from '../shared';
|
|
|
|
| 19 |
constructor(
|
| 20 |
protected globalLogger: GlobalLogger,
|
| 21 |
protected secretExposer: SecretExposer,
|
|
|
|
| 22 |
protected threadLocal: AsyncLocalContext,
|
| 23 |
protected blackHoleDetector: BlackHoleDetector,
|
| 24 |
) {
|
|
|
|
| 47 |
doSearch(variant: 'images', query: SerperSearchQueryParams): Promise<SerperImageSearchResponse>;
|
| 48 |
doSearch(variant: 'news', query: SerperSearchQueryParams): Promise<SerperNewsSearchResponse>;
|
| 49 |
async doSearch(variant: 'web' | 'images' | 'news', query: SerperSearchQueryParams) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
const clientIt = this.iterClient();
|
| 51 |
let client = clientIt.next().value;
|
| 52 |
if (!client) {
|