🐛 fix: 修正返回结果导致插件无法正常识别的问题

This commit is contained in:
arvinxx
2023-07-30 01:00:08 +08:00
parent 9ce5d1d563
commit b1831889a8
2 changed files with 37 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
import { PluginRunner } from '@/plugins/type';
import { Result } from './type';
import { ParserResponse, Result } from './type';
const BASE_URL = process.env.BROWSERLESS_URL ?? 'https://chrome.browserless.io';
const BROWSERLESS_TOKEN = process.env.BROWSERLESS_TOKEN;
@@ -34,10 +34,12 @@ const runner: PluginRunner<{ url: string }, Result> = async ({ url }) => {
method: 'POST',
});
return await parseRes.json();
const { title, textContent, siteName } = (await parseRes.json()) as ParserResponse;
return { content: textContent, title, url, website: siteName };
} catch (error) {
console.error(error);
return { content: '抓取失败', errorMessage: (error as any).message };
return { content: '抓取失败', errorMessage: (error as any).message, url };
}
};

View File

@@ -1,5 +1,35 @@
export type Result = {
content?: string;
content: string;
title?: string;
url?: string;
url: string;
website?: string;
};
export interface ParserResponse {
/** author metadata */
byline: string;
/** HTML string of processed article content */
content: string;
/** content direction */
dir: string;
/** article description, or short excerpt from the content */
excerpt: string;
/** content language */
lang: string;
/** length of an article, in characters */
length: number;
/** name of the site */
siteName: string;
/** text content of the article, with all the HTML tags removed */
textContent: string;
/** article title */
title: string;
}