Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place

make subfs fetching recursive on hosting-service

nekomimi.pet 2e1a9c02 75f9efeb

verified
Changed files
+15 -4
apps
hosting-service
src
lib
+15 -4
apps/hosting-service/src/lib/utils.ts
··· 181 /** 182 * Replace subfs nodes in a directory tree with their actual content 183 * Subfs entries are "merged" - their root entries are hoisted into the parent directory 184 */ 185 - async function expandSubfsNodes(directory: Directory, pdsEndpoint: string): Promise<Directory> { 186 // Extract all subfs URIs 187 const subfsUris = extractSubfsUris(directory); 188 ··· 191 return directory; 192 } 193 194 - console.log(`Found ${subfsUris.length} subfs records, fetching...`); 195 196 // Fetch all subfs records in parallel 197 const subfsRecords = await Promise.all( ··· 225 const subfsEntries = subfsMap.get(fullPath); 226 227 if (subfsEntries) { 228 - console.log(`Merging subfs node at ${fullPath} (${subfsEntries.length} entries, flat: ${isFlat})`); 229 230 if (isFlat) { 231 // Flat merge: hoist entries directly into parent directory ··· 265 return result; 266 } 267 268 - return { 269 ...directory, 270 entries: replaceSubfsInEntries(directory.entries) 271 }; 272 } 273 274
··· 181 /** 182 * Replace subfs nodes in a directory tree with their actual content 183 * Subfs entries are "merged" - their root entries are hoisted into the parent directory 184 + * This function is recursive - it will keep expanding until no subfs nodes remain 185 */ 186 + async function expandSubfsNodes(directory: Directory, pdsEndpoint: string, depth: number = 0): Promise<Directory> { 187 + const MAX_DEPTH = 10; // Prevent infinite loops 188 + 189 + if (depth >= MAX_DEPTH) { 190 + console.error('Max subfs expansion depth reached, stopping to prevent infinite loop'); 191 + return directory; 192 + } 193 + 194 // Extract all subfs URIs 195 const subfsUris = extractSubfsUris(directory); 196 ··· 199 return directory; 200 } 201 202 + console.log(`[Depth ${depth}] Found ${subfsUris.length} subfs records, fetching...`); 203 204 // Fetch all subfs records in parallel 205 const subfsRecords = await Promise.all( ··· 233 const subfsEntries = subfsMap.get(fullPath); 234 235 if (subfsEntries) { 236 + console.log(`[Depth ${depth}] Merging subfs node at ${fullPath} (${subfsEntries.length} entries, flat: ${isFlat})`); 237 238 if (isFlat) { 239 // Flat merge: hoist entries directly into parent directory ··· 273 return result; 274 } 275 276 + const partiallyExpanded = { 277 ...directory, 278 entries: replaceSubfsInEntries(directory.entries) 279 }; 280 + 281 + // Recursively expand any remaining subfs nodes (e.g., nested subfs inside parent subfs) 282 + return expandSubfsNodes(partiallyExpanded, pdsEndpoint, depth + 1); 283 } 284 285