diff --git a/apps/server/etapi.openapi.yaml b/apps/server/etapi.openapi.yaml index af05bdbe5..8b8a65f2b 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: noteId diff --git a/apps/server/src/etapi/attachments.ts b/apps/server/src/etapi/attachments.ts index f8fd9c16d..48cccec29 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],