ETAPI put content

This commit is contained in:
zadam
2022-01-08 12:01:54 +01:00
parent 2532ea525d
commit c5366abf75
7 changed files with 88 additions and 37 deletions

View File

@@ -13,19 +13,6 @@ function register(router) {
res.json(mappers.mapNoteToPojo(note));
});
ru.route(router, 'get', '/etapi/notes/:noteId/content', (req, res, next) => {
const note = ru.getAndCheckNote(req.params.noteId);
const filename = utils.formatDownloadTitle(note.title, note.type, note.mime);
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader('Content-Type', note.mime);
res.send(note.getContent());
});
ru.route(router, 'post' ,'/etapi/create-note', (req, res, next) => {
const params = req.body;
@@ -67,7 +54,7 @@ function register(router) {
const note = becca.getNote(noteId);
if (!note) {
if (!note || note.isDeleted) {
return res.sendStatus(204);
}
@@ -75,6 +62,27 @@ function register(router) {
res.sendStatus(204);
});
ru.route(router, 'get', '/etapi/notes/:noteId/content', (req, res, next) => {
const note = ru.getAndCheckNote(req.params.noteId);
const filename = utils.formatDownloadTitle(note.title, note.type, note.mime);
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader('Content-Type', note.mime);
res.send(note.getContent());
});
ru.route(router, 'put', '/etapi/notes/:noteId/content', (req, res, next) => {
const note = ru.getAndCheckNote(req.params.noteId);
note.setContent(req.body);
return res.sendStatus(204);
});
}
module.exports = {