mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
add removing feature
This commit is contained in:
@@ -25,27 +25,50 @@ app.post('/api/pdf/generate/:template', (req, res) => {
|
||||
.then(() => id);
|
||||
})
|
||||
.then(id => {
|
||||
res.send({id: id});
|
||||
res.end();
|
||||
res
|
||||
.status(200)
|
||||
.json({id: id});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Error:', err, 'for', req.url);
|
||||
res.sendStatus(500).end(err);
|
||||
res
|
||||
.status(500)
|
||||
.json({error: err.toString()});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/pdf/latest', (req, res) => {
|
||||
store
|
||||
.list()
|
||||
.then(results => res.json(results))
|
||||
.catch(err => res.sendStatus(500).end(err));
|
||||
.then(results => res
|
||||
.status(200)
|
||||
.json(results)
|
||||
)
|
||||
.catch(err => res
|
||||
.status(500)
|
||||
.json({error: err.toString()})
|
||||
);
|
||||
});
|
||||
|
||||
app.delete('/api/pdf/latest/:id', (req, res) => {
|
||||
const { id } = req.params;
|
||||
console.log(`Deleting ${id}...`);
|
||||
store
|
||||
.remove(id)
|
||||
.then(() => res.sendStatus(202))
|
||||
.catch(err => res
|
||||
.status(500)
|
||||
.json({error: err.toString()})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
app.options('/api/pdf/:id');
|
||||
app.get('/api/pdf/:id', (req, res) => {
|
||||
const {id} = req.params;
|
||||
res.sendFile(getPdfPath(id));
|
||||
res
|
||||
.status(200)
|
||||
.sendFile(getPdfPath(id));
|
||||
});
|
||||
|
||||
app.use(express.static('../client/build'));
|
||||
|
||||
@@ -9,12 +9,14 @@ const sortBy = require('lodash.sortby');
|
||||
const list = promisify(store.list);
|
||||
const load = promisify(store.load);
|
||||
const add = promisify(store.add);
|
||||
const remove = promisify(store.remove);
|
||||
|
||||
module.exports = {
|
||||
list: () => list()
|
||||
.then(result => sortBy(result, 'created').reverse()),
|
||||
load: id => load(id),
|
||||
add: item => add(item),
|
||||
remove: id => remove(id),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user