Major preformance fix.

This commit is contained in:
Daniel 2022-06-05 21:42:49 +04:30
parent b907bd53ec
commit b3e6e75f90
4 changed files with 18 additions and 7 deletions

View File

@ -5,6 +5,7 @@ const cors = require('cors');
const config = require('../src/config.js');
const getData = require('./modules/getData.js');
const fs = require('fs');
const fetch = require('cross-fetch');
const port = config.API.PORT;
@ -35,16 +36,27 @@ app.get('/pdfs/:id', async (req, res) => {
app.post('/api', async (req, res) => {
const pageToVisit = req.body.link;
const id = req.body._id;
const getTitle = async(url) => {
let body;
await fetch(url)
.then(res => res.text())
.then(text => body = text)
// regular expression to parse contents of the <title> tag
let match = body.match(/<title>([^<]*)<\/title>/);
return match[1];
}
try {
req.body.title = await getTitle(req.body.link);
await insertDoc(req.body);
res.send("DONE!");
const dataResult = await getData(pageToVisit, req.body._id);
req.body.title = dataResult;
insertDoc(req.body);
} catch (err) {
console.log(err);
insertDoc(req.body);
} finally {
res.send('Posted!');
}
});

View File

@ -37,7 +37,6 @@
}
.list-entity-content {
text-shadow: 0px 1px 3px #1f2c38;
z-index: 0;
margin-left: 70px;
padding: 20px;

View File

@ -6,5 +6,5 @@
.seperator {
width: 100%;
color: white;
color: #1f2c38;
}

View File

@ -6,9 +6,9 @@ body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #1f2c38;
text-shadow: 0px 1px 1px #1f2c38;
}
*::selection {
background-color: rgba(255, 255, 0, 0.6);
text-shadow: 0px 1px 3px #1f2c38;
}