forked from TypingMind/plugin-web-page-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementation.js
More file actions
34 lines (28 loc) · 907 Bytes
/
implementation.js
File metadata and controls
34 lines (28 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
async function fetchPageContent(url, pluginServer) {
const response = await fetch(
`${pluginServer}/get-content?url=${encodeURIComponent(url)}`
);
if (!response.ok) {
throw new Error(
`Failed to fetch web content: ${response.status} - ${response.statusText}`
);
}
const data = await response.json();
return data.responseObject;
}
async function read_web_page_content(params, userSettings) {
const { url } = params;
const { pluginServer } = userSettings;
if (!pluginServer) {
throw new Error(
'Missing plugin server URL. Please set it in the plugin settings.'
);
}
const cleanPluginServer = pluginServer.replace(/\/$/, '');
try {
return await fetchPageContent(url, cleanPluginServer);
} catch (error) {
console.error('Error summarizing webpage:', error);
return 'Error: Unable to generate a summary. Please try again later.';
}
}