Skip to content

Commit a99ab84

Browse files
committed
fix: remove express base url from the uploaded image key, if was uploaded image, that starts with "/"
https://web.tracklify.com/project/2b7ZVgE5/AdminForth/1385/WTyzAPZ6/markdown-plugin-saves-invalid-
1 parent 89d9cb0 commit a99ab84

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,14 @@ export default class MarkdownPlugin extends AdminForthPlugin {
162162
return u.pathname.replace(/^\/+/, '');
163163
} catch {
164164
// Fallback: strip scheme/host if it looks like a URL, otherwise treat as a path.
165-
return stripQueryAndHash(url).replace(/^https?:\/\/[^\/]+\/+/, '').replace(/^\/+/, '');
165+
const key = stripQueryAndHash(url).replace(/^https?:\/\/[^\/]+\/+/, '').replace(/^\/+/, '');
166+
167+
// since only local storage adapter returns non-URL paths
168+
// we need to cut-off express-base
169+
// e.g. /uploaded-static/cars_description_images-74bbe25a154500c4a2fcb91fb91cea75/sqlite/images_1775114133312.webp
170+
// should become /sqlite/images_1775114133312.webp
171+
const cutted = key.split("/").filter(Boolean).slice(2).join("/");
172+
return cutted;
166173
}
167174
};
168175

0 commit comments

Comments
 (0)