Skip to content

Commit

Permalink
Fool-proofing the website
Browse files Browse the repository at this point in the history
  • Loading branch information
koen-ongena-imec committed Jul 14, 2022
1 parent 1a1543a commit b6fd1e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/handlers/homeViewHandler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const { parsePdfFile } = require('./pdfHandler');

const post = async (req, res) => {
const { pdf } = req.files;
const data = await parsePdfFile(pdf);

res.status(200).render('index', { values: data, filename: pdf.name });
const post = (req, res) => {
if (!req.files) {
res.status(400);
} else {
const { pdf } = req.files;
parsePdfFile(pdf).then((data) => {
res.status(200).render('index', { values: data, filename: pdf.name });
}).catch(() => {
res.status(500).render('index', { error: 'Something went wrong. Are you sure this is a valid PDF?' });
});
}
};

const get = async (req, res) => {
Expand Down
9 changes: 7 additions & 2 deletions src/views/index.handlebars
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<div class="container">
{{#if error }}
<div class="alert alert-danger show" role="alert">
{{error}}
</div>
{{/if}}

<form action="/" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="formFile" class="form-label">Resmed PDF file:</label>
<input class="form-control" type="file" id="pdf" name="pdf">
<input required class="form-control" type="file" id="pdf" name="pdf">
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>

{{#if values.length }}
<hr>

Expand Down

0 comments on commit b6fd1e0

Please sign in to comment.