Skip to content

Commit e940f47

Browse files
committed
added /cleanup that returns both html and plaintext
1 parent f7011af commit e940f47

1 file changed

Lines changed: 4 additions & 32 deletions

File tree

server.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ app.get("/plain_text", async (req, res) => {
2929
});
3030

3131

32-
app.get("/readable_html", async (req, res) => {
32+
app.get("/cleanup", async (req, res) => {
3333
const { url } = req.query;
3434
console.log(req.query);
3535

3636
const start = process.hrtime();
3737

38-
const content = await advanced_readability_cleanup(url);
38+
const html = await advanced_readability_cleanup(url);
3939

4040
// Send the cleaned up content as the response
41-
res.send(content);
41+
res.send({html: html, text: HTML2Text(html)});
4242

4343
// Calculate the execution time
4444
const end = process.hrtime(start);
@@ -47,34 +47,7 @@ app.get("/readable_html", async (req, res) => {
4747
console.log(`Request for ${url} took ${executionTime}`);
4848
});
4949

50-
app.get("/readable_html_verbose", async (req, res) => {
51-
const { url } = req.query;
52-
console.log(req.query);
53-
54-
if (!url) {
55-
return res.status(400).send("Missing 'url' parameter");
56-
}
57-
58-
console.log(`Request received for URL: ${url}`);
5950

60-
const start = process.hrtime();
61-
62-
try {
63-
const content = await advanced_readability_cleanup(url);
64-
65-
// Send the cleaned up content as the response
66-
res.send(content);
67-
68-
// Calculate the execution time
69-
const end = process.hrtime(start);
70-
const executionTime = `${end[0]}s ${end[1] / 1000000}ms`;
71-
72-
console.log(`Request for ${url} took ${executionTime}`);
73-
} catch (error) {
74-
console.error(`Error processing request for ${url}:`, error);
75-
res.status(500).send("Error processing request");
76-
}
77-
});
7851

7952

8053
app.get("/old_cleanup", async (req, res) => {
@@ -97,8 +70,7 @@ app.get("/old_cleanup", async (req, res) => {
9770

9871

9972
// Start the server
100-
const port = 3000;
73+
const port = 3001;
10174
app.listen(port, () => {
102-
console.log("hello!")
10375
console.log(`Server is running on http://localhost:${port}`);
10476
});

0 commit comments

Comments
 (0)