fix: thumbnails via image() relative to appHome, paste dir from appHome

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 12:09:32 +01:00
1 parent dd95bf2c68
commit 65b66f86cd
3 files changed
+60 -6

No files matched your search

+23
View File
@@ -192,3 +192,26 @@ export function formatBytes(bytes) {
if (bytes < 1024 * 1024 * 1024) return unit(bytes / 1024 / 1024, "MB");
return unit(bytes / 1024 / 1024 / 1024, "GB");
}
/**
* The path of a file relative to a folder - or nothing when the file is not
* inside it.
*
* `image()` draws only files of the application's own folder, and wants their
* path relative to it (forward slashes). Windows paths compare without regard
* to case and to the kind of slash.
*
* @param {string} base - the folder (`appHome()`)
* @param {string} path - the file
* @returns {string|null}
*/
export function relativeTo(base, path) {
if (typeof base !== "string" || typeof path !== "string" || base === "" || path === "") return null;
const clean = (text) => text.replace(/\\/g, "/").replace(/\/+$/, "");
const root = clean(base);
const file = clean(path);
if (file.length <= root.length + 1) return null;
if (file.slice(0, root.length).toLowerCase() !== root.toLowerCase()) return null;
if (file[root.length] !== "/") return null;
return file.slice(root.length + 1);
}