diff --git a/app/src/components/plugins/file.tsx b/app/src/components/plugins/file.tsx index 721f271..4b82c69 100644 --- a/app/src/components/plugins/file.tsx +++ b/app/src/components/plugins/file.tsx @@ -1,5 +1,5 @@ import { Download, Eye, File } from "lucide-react"; -import { saveAsFile, saveBlobAsFile } from "@/utils/dom.ts"; +import { saveAsFile, saveBlobAsFile, saveImageAsFile } from "@/utils/dom.ts"; import { useMemo } from "react"; import { Button } from "@/components/ui/button.tsx"; import FileViewer from "@/components/FileViewer.tsx"; @@ -15,11 +15,16 @@ import FileViewer from "@/components/FileViewer.tsx"; export function parseFile(data: string, acceptDownload?: boolean) { const filename = data.split("\n")[0].replace("[[", "").replace("]]", ""); const content = data.replace(`[[${filename}]]\n`, ""); + const image = useMemo(() => { // get image url from content (like: https://i.imgur.com/xxxxx.png) - const match = content - .toLowerCase() - .match(/(https?:\/\/.*\.(?:png|jpg|jpeg|gif))/); + const match = content.match(/(https?:\/\/.*\.(?:png|jpg|jpeg|gif))/); + return match ? match[0] : ""; + }, [filename, content]); + + const b64image = useMemo(() => { + // get base64 image from content (like: data:image/png;base64,xxxxx) + const match = content.match(/(data:image\/.*;base64,.*=)/); return match ? match[0] : ""; }, [filename, content]); @@ -38,12 +43,16 @@ export function parseFile(data: string, acceptDownload?: boolean) { {filename}
- {image ? ( + {image || b64image ? (
{image && {""}} + {b64image && {""}} ); } diff --git a/utils/config.go b/utils/config.go index 076f897..3c849e4 100644 --- a/utils/config.go +++ b/utils/config.go @@ -50,6 +50,9 @@ func RegisterStaticRoute(engine *gin.Engine) { // static files are in ~/app/dist if !viper.GetBool("serve_static") { + engine.NoRoute(func(c *gin.Context) { + c.JSON(404, gin.H{"status": false, "message": "not found or method not allowed"}) + }) return }