2023-06-18 21:20:52 +00:00
|
|
|
import express from "express";
|
|
|
|
import { Readability } from "@mozilla/readability";
|
|
|
|
import { JSDOM } from "jsdom";
|
|
|
|
import got from "got";
|
2023-06-18 22:44:17 +00:00
|
|
|
import path from "path";
|
|
|
|
import { fileURLToPath } from "url";
|
2023-06-18 21:20:52 +00:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const port = 5763;
|
|
|
|
|
2023-06-18 22:46:43 +00:00
|
|
|
// @ts-ignore
|
2023-06-18 22:44:17 +00:00
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
|
|
let url: string
|
|
|
|
|
2023-06-18 21:20:52 +00:00
|
|
|
app.get("/", (req, res) => {
|
2023-06-18 22:44:17 +00:00
|
|
|
url = req.query.at as string;
|
2023-06-18 21:20:52 +00:00
|
|
|
|
|
|
|
if (!url) {
|
2023-06-18 22:44:17 +00:00
|
|
|
res.sendFile(path.join(__dirname + "/dist/index.html"));
|
2023-06-18 21:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
got(url)
|
|
|
|
.then((response) => {
|
|
|
|
const dom = new JSDOM(response.body);
|
|
|
|
let reader = new Readability(dom.window.document);
|
|
|
|
let article = reader.parse();
|
|
|
|
|
|
|
|
if (!article) {
|
|
|
|
res.send("Something went wrong");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.send(article.content);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
});
|