feat: simplify public shares and add compact link management

This commit is contained in:
SantaSpeen committed 2026-10-22 00:58:05 +03:00
1 parent 5dda0dc5f3
commit 7fc7465f71
15 files changed
+417 -273

No files matched your search

@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";
import { breadcrumbItems, shareBase } from "../breadcrumbs";
describe("public share breadcrumbs", () => {
for (const prefix of ["s", "share"]) {
it(`hides the key and prefix for /${prefix} links`, () => {
const root = `/${prefix}/YEZDVdfvYkDRjjkKUnMtIQ`;
expect(breadcrumbItems(root, shareBase(root))).toEqual([]);
const path = root + "/CT20261015_121353_9093_96834755";
expect(breadcrumbItems(path, shareBase(path))).toEqual([
{ name: "CT20261015_121353_9093_96834755", url: path + "/" },
]);
});
}
it("keeps nested encoded paths relative to the public root", () => {
const path = "/share/key/Scan%20A/image.dcm";
expect(breadcrumbItems(path, shareBase(path))).toEqual([
{ name: "Scan A", url: "/share/key/Scan%20A/" },
{ name: "image.dcm", url: path + "/" },
]);
});
it("only removes a matching path prefix", () => {
expect(breadcrumbItems("/files-archive/example", "/files")).toEqual([]);
expect(breadcrumbItems("/files/Documents/", "/files")).toEqual([
{ name: "Documents", url: "/files/Documents/" },
]);
});
});
+19
View File
@@ -0,0 +1,19 @@
export function shareBase(path: string): string {
return path.match(/^\/(?:s|share)\/[^/]+/)?.[0] ?? "/s";
}
export function breadcrumbItems(path: string, base: string): BreadCrumb[] {
base = base.replace(/\/+$/, "");
const relative = path.startsWith(base + "/") ? path.slice(base.length) : "";
const parts = relative.split("/").filter(Boolean);
const items = parts.map((part, index) => ({
name: decodeURIComponent(part),
url: base + "/" + parts.slice(0, index + 1).join("/") + "/",
}));
if (items.length > 4) {
const visible = items.slice(-4);
visible[0] = { ...visible[0], name: "..." };
return visible;
}
return items;
}