From 164c89d36217e7aec781d26081311acb16c1c7fa Mon Sep 17 00:00:00 2001 From: Adam French Date: Tue, 13 Jan 2026 12:23:36 +0000 Subject: [PATCH] adjust frontend for any filetype and add metadata to api response --- backend/handlers/handle_notes.go | 15 +++++++++--- nginx/vue/src/views/Notes.vue | 42 +++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/backend/handlers/handle_notes.go b/backend/handlers/handle_notes.go index 17cdb7e..e80fc52 100644 --- a/backend/handlers/handle_notes.go +++ b/backend/handlers/handle_notes.go @@ -2,7 +2,7 @@ package handlers import ( "net/http" - "path/filepath" + "os" "github.com/gin-gonic/gin" ) @@ -16,7 +16,14 @@ func (store *Store) GetNoteFile(ctx *gin.Context) { return } - // Get the filename from path - filename := filepath.Base(path) - ctx.FileAttachment(path, filename) + info, err := os.Stat(path) + if err != nil { + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + + ctx.Header("Last-Modified", info.ModTime().UTC().Format(http.TimeFormat)) + ctx.Header("Access-Control-Expose-Headers", "Content-Disposition, Last-Modified") + + ctx.FileAttachment(path, info.Name()) } diff --git a/nginx/vue/src/views/Notes.vue b/nginx/vue/src/views/Notes.vue index 863b378..e9f804d 100644 --- a/nginx/vue/src/views/Notes.vue +++ b/nginx/vue/src/views/Notes.vue @@ -2,19 +2,34 @@ import Markdown from "@/components/quick/Markdown.vue"; import { ref, onMounted } from "vue"; import axios from "axios"; +import { useRoute } from "vue-router"; -const note = ref(null); +const file = ref(null); +const filename = ref(""); +const last_edited = ref(null); -function fixContents(contents) { - // Obsidian notes have links in the form [[link|name]] - // contents so that they are rendered correctly - return contents.replace(/\[\[(.*?)\|(.*)\]\]/g, '$2'); +// if the address is https://www.adam-french.co.uk/notes/PATH +// request from https://www.adam-french.co.uk/api/notes/PATH +const route = useRoute(); +const path = route.params.path; +const url = `/api/notes/${path}`; + +function getFilename(headers) { + const disposition = headers["content-disposition"]; + if (!disposition) return null; + + const match = disposition.match(/filename="?([^"]+)"?/); + return match ? match[1] : null; } -async function fetchNote() { - const response = await axios.get("/api/notes/Index"); - response.data.contents = fixContents(response.data.contents); - note.value = response.data; +async function fetchFile() { + const response = await axios.get(url, { responseType: "blob" }); + filename.value = getFilename(response.headers); + + const lastModified = response.headers["last-modified"]; + last_edited.value = lastModified ? new Date(lastModified) : null; + + file.value = response.data; } onMounted(fetchNote); @@ -23,14 +38,13 @@ onMounted(fetchNote);