mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
store json after every generate
This commit is contained in:
@@ -3,8 +3,8 @@ const bodyParser = require('body-parser');
|
||||
const app = express();
|
||||
const templates = require('./templates');
|
||||
const renderer = require('./renderer');
|
||||
|
||||
const {getPdfPath} = require('./utils');
|
||||
const store = require('./store');
|
||||
const { getPdfPath } = require('./utils');
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
@@ -15,6 +15,15 @@ app.post('/api/pdf/generate/:template', (req, res) => {
|
||||
|
||||
templates.get(templateName, options)
|
||||
.then(renderer)
|
||||
.then(id => {
|
||||
const storeData = Object.assign({}, options, {
|
||||
id,
|
||||
created: new Date().toISOString()
|
||||
});
|
||||
return store
|
||||
.add(storeData)
|
||||
.then(() => id);
|
||||
})
|
||||
.then(id => {
|
||||
res.send({id: id});
|
||||
res.end();
|
||||
@@ -25,6 +34,14 @@ app.post('/api/pdf/generate/:template', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/pdf/latest', (req, res) => {
|
||||
store
|
||||
.list()
|
||||
.then(results => res.json(results))
|
||||
.catch(err => res.sendStatus(500).end(err));
|
||||
});
|
||||
|
||||
|
||||
app.options('/api/pdf/:id');
|
||||
app.get('/api/pdf/:id', (req, res) => {
|
||||
const {id} = req.params;
|
||||
|
||||
Reference in New Issue
Block a user