MCPcopy Create free account
hub / github.com/cifertech/DisplayKit / fetchDirListingPngFiles

Function fetchDirListingPngFiles

app.js:2886–2911  ·  view source on GitHub ↗
(dirHref)

Source from the content-addressed store, hash-verified

2884}
2885
2886async function fetchDirListingPngFiles(dirHref) {
2887 try {
2888 const res = await fetch(`${dirHref}?v=${Date.now()}`, { cache: "no-store" });
2889 if (!res.ok) return [];
2890 const text = await res.text();
2891 // Parse Apache/python http.server listings (simple HTML with <a href="...">)
2892 const doc = new DOMParser().parseFromString(text, "text/html");
2893 const anchors = Array.from(doc.querySelectorAll("a[href]"));
2894 const files = anchors
2895 .map((a) => a.getAttribute("href") || "")
2896 .filter((href) => href && !href.startsWith("?") && !href.startsWith("#"))
2897 .map((href) => href.replace(/\\/g, "/"))
2898 .filter((href) => href.toLowerCase().endsWith(".png"))
2899 // decode URL-encoded names from listing
2900 .map((href) => {
2901 try { return decodeURIComponent(href); } catch { return href; }
2902 })
2903 // drop any path segments, keep filename only
2904 .map((href) => (href.split("/").pop() || href).trim())
2905 .filter(Boolean);
2906 // Deduplicate
2907 return Array.from(new Set(files));
2908 } catch {
2909 return [];
2910 }
2911}
2912
2913async function tryLoadIconsFromDirectoryListing() {
2914 // Try known size folders; if they don't exist or listing is disabled, we'll fall back.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected