From 4c1bebb4683639f01ae1c9ae551441103a247c1d Mon Sep 17 00:00:00 2001 From: wassfila Date: Sun, 8 Dec 2024 12:32:28 +0100 Subject: [PATCH] bugfix abs markdown in linux --- .gitignore | 1 + package.json | 2 +- src/pages/assets/[...path].js | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f4c4f01..34edaba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.astro dist .structure/ public/menu.json diff --git a/package.json b/package.json index 6c826ec..17f1265 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@google/model-viewer": "^3.4.0", "@svgdotjs/svg.js": "^3.1.2", "astro": "^4.5.10", - "content-structure": "^1.1.8", + "content-structure": "^1.1.10", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "datatables.net-dt": "^1.13.7", diff --git a/src/pages/assets/[...path].js b/src/pages/assets/[...path].js index 10305b4..f316147 100644 --- a/src/pages/assets/[...path].js +++ b/src/pages/assets/[...path].js @@ -2,7 +2,7 @@ import { createReadStream } from 'fs'; import {resolve,join} from 'path' import { config } from "@/config"; import {load_json_abs} from '@/libs/utils.js' -import {file_mime} from '@/libs/assets.js' +import {exists, file_mime} from '@/libs/assets.js' import {remove_base} from '@/libs/assets.js' export async function GET({params}){ @@ -14,7 +14,16 @@ export async function GET({params}){ imagePath = resolve(join(config.rootdir,"public",params.path)); } imagePath = remove_base(imagePath) - console.log(`assets> serving '${imagePath}'`) + //due to a markdown limitation, abs assets are stripped of starting '/' in linux + //workaround : if the file does not exist, then try the public + if(! await exists(imagePath)){ + imagePath = resolve(join(config.rootdir,"public",params.path)); + } + if(! await exists(imagePath)){ + console.log(`\nassets> * NOT FOUND ${params.path}`) + }else{ + console.log(`\nassets> serving '${imagePath}'`) + } try { const stream = createReadStream(imagePath); const contentType = file_mime(imagePath)