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