mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
ETAPI put content
This commit is contained in:
parent
2532ea525d
commit
c5366abf75
@ -49,7 +49,7 @@ function register(router) {
|
||||
ru.route(router, 'delete' ,'/etapi/attributes/:attributeId', (req, res, next) => {
|
||||
const attribute = becca.getAttribute(req.params.attributeId);
|
||||
|
||||
if (!attribute) {
|
||||
if (!attribute || attribute.isDeleted) {
|
||||
return res.sendStatus(204);
|
||||
}
|
||||
|
||||
@ -61,4 +61,4 @@ function register(router) {
|
||||
|
||||
module.exports = {
|
||||
register
|
||||
};
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ function register(router) {
|
||||
ru.route(router, 'delete' ,'/etapi/branches/:branchId', (req, res, next) => {
|
||||
const branch = becca.getBranch(req.params.branchId);
|
||||
|
||||
if (!branch) {
|
||||
if (!branch || branch.isDeleted) {
|
||||
return res.sendStatus(204);
|
||||
}
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -46,11 +46,17 @@ DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "ATTRIBUTE_NOT_FOUND");
|
||||
%}
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND");
|
||||
%}
|
||||
|
@ -49,13 +49,19 @@ DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "BRANCH_NOT_FOUND");
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "BRANCH_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
@ -68,4 +74,4 @@ GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
|
||||
> {% client.assert(response.status === 200, "Response status is not 200"); %}
|
||||
> {% client.assert(response.status === 200, "Response status is not 200"); %}
|
||||
|
@ -70,21 +70,27 @@ DELETE {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "BRANCH_NOT_FOUND");
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "BRANCH_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "BRANCH_NOT_FOUND");
|
||||
%}
|
||||
|
||||
@ -92,16 +98,16 @@ GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "NOTE_NOT_FOUND");
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "NOTE_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "ATTRIBUTE_NOT_FOUND");
|
||||
%}
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND");
|
||||
%}
|
||||
|
25
test-etapi/put-note-content.http
Normal file
25
test-etapi/put-note-content.http
Normal file
@ -0,0 +1,25 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "code",
|
||||
"mime": "text/plain",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/notes/{{createdNoteId}}/content
|
||||
Content-Type: text/plain
|
||||
|
||||
Changed content
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}/content
|
||||
|
||||
> {% client.assert(response.body === "Changed content"); %}
|
Loading…
x
Reference in New Issue
Block a user