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
refactor(core): get rid of as any for image routes
Elian Doran3ad20e43f10f
diff --git a/packages/trilium-core/src/routes/api/attachments.ts b/packages/trilium-core/src/routes/api/attachments.tsindex 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<P> = Omit<Request<P>, "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.tsindex 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<P> = Omit<Request<P>, "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);