Commit cd5e6ef0 authored by nanahira's avatar nanahira

support multiple search

parent 6aff4237
Pipeline #14763 passed with stages
in 3 minutes and 42 seconds
...@@ -4,15 +4,16 @@ import { TwintData, TwintReturn } from '../dto/hami.dto'; ...@@ -4,15 +4,16 @@ import { TwintData, TwintReturn } from '../dto/hami.dto';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
import { AxiosRequestConfig } from 'axios'; import { AxiosRequestConfig } from 'axios';
import _ from 'lodash';
@Injectable() @Injectable()
export class HamiFetcherService extends ConsoleLogger { export class HamiFetcherService extends ConsoleLogger {
private readonly twintUrl: string = this.config.get('twintUrl'); private readonly twintUrl: string = this.config.get('twintUrl');
private readonly twintToken: string = this.config.get('twintToken'); private readonly twintToken: string = this.config.get('twintToken');
private readonly hamiUsername: string = this.config.get('hamiUsername'); private readonly hamiUsername: string = this.config.get('hamiUsername');
private readonly hamiBlacklistSearch: string = this.config.get( private readonly hamiBlacklistSearches: string[] = this.config
'hamiBlacklistSearch', .get('hamiBlacklistSearch')
); ?.split(',');
constructor(private http: HttpService, private config: ConfigService) { constructor(private http: HttpService, private config: ConfigService) {
super('HamiFetcherService'); super('HamiFetcherService');
} }
...@@ -27,14 +28,17 @@ export class HamiFetcherService extends ConsoleLogger { ...@@ -27,14 +28,17 @@ export class HamiFetcherService extends ConsoleLogger {
}; };
} }
async fetchBlacklist(Since?: string): Promise<TwintData[]> { async fetchBlacklistSingle(
Search: string,
Since?: string,
): Promise<TwintData[]> {
try { try {
const { data } = await lastValueFrom( const { data } = await lastValueFrom(
this.http.post<TwintReturn>( this.http.post<TwintReturn>(
`${this.twintUrl}/Search`, `${this.twintUrl}/Search`,
{ {
Username: this.hamiUsername, Username: this.hamiUsername,
Search: this.hamiBlacklistSearch, Search,
Since, Since,
}, },
this.axiosConfig(), this.axiosConfig(),
...@@ -46,4 +50,17 @@ export class HamiFetcherService extends ConsoleLogger { ...@@ -46,4 +50,17 @@ export class HamiFetcherService extends ConsoleLogger {
return []; return [];
} }
} }
async fetchBlacklist(Since?: string): Promise<TwintData[]> {
return _.uniqBy(
_.flatten(
await Promise.all(
this.hamiBlacklistSearches.map((search) =>
this.fetchBlacklistSingle(search, Since),
),
),
),
(tweet) => tweet.id_str,
);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment