mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader
synced 2025-08-16 05:55:52 +08:00
chore: refactor code
This commit is contained in:
parent
79b8bde9cc
commit
72d095098d
@ -550,10 +550,7 @@ export class SearcherHost extends RPCHost {
|
||||
break;
|
||||
}
|
||||
case 'wechat':{
|
||||
r = await this.wechatSearchService.search({
|
||||
kw: query.q,
|
||||
page: query.page,
|
||||
});
|
||||
r = await this.wechatSearchService.search(query);
|
||||
break;
|
||||
}
|
||||
case 'web':
|
||||
|
@ -2,7 +2,8 @@ import { singleton } from 'tsyringe';
|
||||
import { GlobalLogger } from './logger';
|
||||
import { AsyncService, DownstreamServiceFailureError, marshalErrorLike } from 'civkit';
|
||||
import { SecretExposer } from '../shared/services/secrets';
|
||||
import { WechatBlogQueryParams, WechatSearchHTTP } from '../shared/3rd-party/wechat-search';
|
||||
import { DajalaWechatSearchHttp, WechatSearchHTTP } from '../shared/3rd-party/wechat-search';
|
||||
import { SerperSearchQueryParams } from '../shared/3rd-party/serper-search';
|
||||
|
||||
|
||||
@singleton()
|
||||
@ -10,7 +11,7 @@ export class WechatSearchService extends AsyncService {
|
||||
|
||||
logger = this.globalLogger.child({ service: this.constructor.name });
|
||||
|
||||
wechatSearchHTTP!: WechatSearchHTTP;
|
||||
dajalaWechatSearchHttp!: DajalaWechatSearchHttp;
|
||||
|
||||
constructor(
|
||||
protected globalLogger: GlobalLogger,
|
||||
@ -23,30 +24,22 @@ export class WechatSearchService extends AsyncService {
|
||||
await this.dependencyReady();
|
||||
this.emit('ready');
|
||||
|
||||
this.wechatSearchHTTP = new WechatSearchHTTP(this.secretExposer.WECHAT_SEARCH_API_KEY);
|
||||
this.dajalaWechatSearchHttp = new DajalaWechatSearchHttp(this.secretExposer.WECHAT_SEARCH_API_KEY);
|
||||
}
|
||||
|
||||
async search(query: WechatBlogQueryParams) {
|
||||
async search(query: SerperSearchQueryParams) {
|
||||
this.logger.info('searching for official account blogs', query);
|
||||
|
||||
const client: WechatSearchHTTP = this.dajalaWechatSearchHttp;
|
||||
try {
|
||||
// get wechat blog search results and convert format
|
||||
const r = await this.wechatSearchHTTP.blogSearch(query);
|
||||
const r = await client.blogSearch(client.transformSerpQuery(query));
|
||||
|
||||
if (r.parsed.code > 100 && r.parsed.code < 200) {
|
||||
throw new DownstreamServiceFailureError({ message: `Search(wechat) failed` });
|
||||
}
|
||||
|
||||
return r.parsed.data?.map((page: any) => {
|
||||
return {
|
||||
title: page.title,
|
||||
link: page.url,
|
||||
content: page.content,
|
||||
snippet: '',
|
||||
publishedTime: page.publish_time,
|
||||
date: page.publish_time_str,
|
||||
};
|
||||
});
|
||||
return client.toSerpResponse(r.parsed);
|
||||
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Wechat search failed: ${err?.message}`, { err: marshalErrorLike(err) });
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit ba27f5425a0fce93bac00690a867dc97a19dccf3
|
||||
Subproject commit 7cf74cc207986ed55d4375c33a8eb9b8a2d30a4e
|
Loading…
x
Reference in New Issue
Block a user