mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
use promises
This commit is contained in:
@@ -10,28 +10,19 @@ app.use(bodyParser.json());
|
||||
|
||||
app.options('/api/pdf/generate/:template');
|
||||
app.post('/api/pdf/generate/:template', (req, res) => {
|
||||
|
||||
const templateName = req.params.template;
|
||||
const options = req.body;
|
||||
|
||||
templates.get(templateName, options, (err, texDocument) => {
|
||||
if (err) {
|
||||
console.error('Error:', err.code, 'for', req.url);
|
||||
res.sendStatus(500).end('Something went wrong while generating Tex source');
|
||||
return;
|
||||
}
|
||||
|
||||
renderer(texDocument, (err, pdfFilePath) => {
|
||||
if (err) {
|
||||
console.error('Error:', err.code, 'for', req.url);
|
||||
res.sendStatus(500).end('Something went wrong while baking the PDF');
|
||||
return;
|
||||
}
|
||||
const id = pdfFilePath.replace('/tmp/', '');
|
||||
templates.get(templateName, options)
|
||||
.then(renderer)
|
||||
.then(id => {
|
||||
res.send({id: id});
|
||||
res.end();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Error:', err, 'for', req.url);
|
||||
res.sendStatus(500).end(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.options('/api/pdf/:id');
|
||||
|
||||
Reference in New Issue
Block a user