Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol.
wisp.place
1import type { Directory } from "@wisp/lexicons/types/place/wisp/fs";
2
3/**
4 * Extract all subfs URIs from a directory tree with their mount paths
5 */
6export function extractSubfsUris(
7 directory: Directory,
8 currentPath: string = ''
9): Array<{ uri: string; path: string }> {
10 const uris: Array<{ uri: string; path: string }> = [];
11
12 for (const entry of directory.entries) {
13 const fullPath = currentPath ? `${currentPath}/${entry.name}` : entry.name;
14
15 if ('type' in entry.node) {
16 if (entry.node.type === 'subfs') {
17 // Subfs node with subject URI
18 const subfsNode = entry.node as any;
19 if (subfsNode.subject) {
20 uris.push({ uri: subfsNode.subject, path: fullPath });
21 }
22 } else if (entry.node.type === 'directory') {
23 // Recursively search subdirectories
24 const subUris = extractSubfsUris(entry.node as Directory, fullPath);
25 uris.push(...subUris);
26 }
27 }
28 }
29
30 return uris;
31}