Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(etapi): add attachments etapi endpoint
perfectra1n808625e564b7
diff --git a/apps/server/etapi.openapi.yaml b/apps/server/etapi.openapi.yamlindex af05bdbe57..8b8a65f2b3 100644--- a/apps/server/etapi.openapi.yaml+++ b/apps/server/etapi.openapi.yaml@@ -362,6 +362,31 @@ paths:application/json; charset=utf-8:schema:$ref: "#/components/schemas/Error"+ /notes/{noteId}/attachments:+ parameters:+ - name: noteId+ in: path+ required: true+ schema:+ $ref: "#/components/schemas/EntityId"+ get:+ description: Returns all attachments for a note identified by its ID+ operationId: getNoteAttachments+ responses:+ "200":+ description: list of attachments+ content:+ application/json; charset=utf-8:+ schema:+ type: array+ items:+ $ref: "#/components/schemas/Attachment"+ default:+ description: unexpected error+ content:+ application/json; charset=utf-8:+ schema:+ $ref: "#/components/schemas/Error"/notes/{noteId}/undelete:parameters:- name: noteIddiff --git a/apps/server/src/etapi/attachments.ts b/apps/server/src/etapi/attachments.tsindex f8fd9c16dc..48cccec29a 100644--- a/apps/server/src/etapi/attachments.ts+++ b/apps/server/src/etapi/attachments.ts@@ -8,6 +8,12 @@ import type { AttachmentRow } from "@triliumnext/commons";import type { ValidatorMap } from "./etapi-interface.js";function register(router: Router) {+ eu.route(router, "get", "/etapi/notes/:noteId/attachments", (req, res, next) => {+ const note = eu.getAndCheckNote(req.params.noteId);+ const attachments = note.getAttachments();+ res.json(attachments.map((attachment) => mappers.mapAttachmentToPojo(attachment)));+ });+const ALLOWED_PROPERTIES_FOR_CREATE_ATTACHMENT: ValidatorMap = {ownerId: [v.notNull, v.isNoteId],role: [v.notNull, v.isString],