From 3ad20e43f10fb9972dad04d50686def4136f4f1f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 12 Apr 2026 18:37:21 +0300 Subject: [PATCH] refactor(core): get rid of as any for image routes --- packages/trilium-core/src/routes/api/attachments.ts | 6 ++++-- packages/trilium-core/src/routes/api/image.ts | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/trilium-core/src/routes/api/attachments.ts b/packages/trilium-core/src/routes/api/attachments.ts index c74dcce1f0..d361b5698a 100644 --- a/packages/trilium-core/src/routes/api/attachments.ts +++ b/packages/trilium-core/src/routes/api/attachments.ts @@ -1,7 +1,9 @@ import { ConvertAttachmentToNoteResponse } from "@triliumnext/commons"; import { ValidationError } from "../../errors"; import type { Request } from "express"; +import type { File } from "../../services/import/common.js"; +type FileRequest

= Omit, "file"> & { file?: File }; import becca from "../../becca/becca.js"; import blobService from "../../services/blob.js"; @@ -44,9 +46,9 @@ function saveAttachment(req: Request<{ noteId: string }>) { note.saveAttachment({ attachmentId, role, mime, title, content }, matchBy); } -function uploadAttachment(req: Request<{ noteId: string }>) { +function uploadAttachment(req: FileRequest<{ noteId: string }>) { const { noteId } = req.params; - const { file } = req as any; // TODO: Add support for file upload in type definitions and remove 'as any' cast + const { file } = req; if (!file) { return { diff --git a/packages/trilium-core/src/routes/api/image.ts b/packages/trilium-core/src/routes/api/image.ts index 71c96c7ed8..48db824d7f 100644 --- a/packages/trilium-core/src/routes/api/image.ts +++ b/packages/trilium-core/src/routes/api/image.ts @@ -1,4 +1,7 @@ import type { Request, Response } from "express"; +import type { File } from "../../services/import/common.js"; + +type FileRequest

= Omit, "file"> & { file?: File }; import becca from "../../becca/becca.js"; import type BNote from "../../becca/entities/bnote.js"; @@ -103,9 +106,9 @@ function returnAttachedImage(req: Request<{ attachmentId: string }>, res: Respon } } -function updateImage(req: Request<{ noteId: string }>) { +function updateImage(req: FileRequest<{ noteId: string }>) { const { noteId } = req.params; - const { file } = req as any; // TODO: Add support for file upload in type definitions and remove 'as any' cast + const { file } = req; const _note = becca.getNoteOrThrow(noteId);