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';
import { ConfigService } from '@nestjs/config';
import { lastValueFrom } from 'rxjs';
import { AxiosRequestConfig } from 'axios';
import _ from 'lodash';
@Injectable()
export class HamiFetcherService extends ConsoleLogger {
private readonly twintUrl: string = this.config.get('twintUrl');
private readonly twintToken: string = this.config.get('twintToken');
private readonly hamiUsername: string = this.config.get('hamiUsername');
private readonly hamiBlacklistSearch: string = this.config.get(
'hamiBlacklistSearch',
);
private readonly hamiBlacklistSearches: string[] = this.config
.get('hamiBlacklistSearch')
?.split(',');
constructor(private http: HttpService, private config: ConfigService) {
super('HamiFetcherService');
}
......@@ -27,14 +28,17 @@ export class HamiFetcherService extends ConsoleLogger {
};
}
async fetchBlacklist(Since?: string): Promise<TwintData[]> {
async fetchBlacklistSingle(
Search: string,
Since?: string,
): Promise<TwintData[]> {
try {
const { data } = await lastValueFrom(
this.http.post<TwintReturn>(
`${this.twintUrl}/Search`,
{
Username: this.hamiUsername,
Search: this.hamiBlacklistSearch,
Search,
Since,
},
this.axiosConfig(),
......@@ -46,4 +50,17 @@ export class HamiFetcherService extends ConsoleLogger {
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