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 181 /** 182 182 * Replace subfs nodes in a directory tree with their actual content 183 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 184 185 */ 185 - async function expandSubfsNodes(directory: Directory, pdsEndpoint: string): Promise<Directory> { 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 + 186 194 // Extract all subfs URIs 187 195 const subfsUris = extractSubfsUris(directory); 188 196 ··· 191 199 return directory; 192 200 } 193 201 194 - console.log(`Found ${subfsUris.length} subfs records, fetching...`); 202 + console.log(`[Depth ${depth}] Found ${subfsUris.length} subfs records, fetching...`); 195 203 196 204 // Fetch all subfs records in parallel 197 205 const subfsRecords = await Promise.all( ··· 225 233 const subfsEntries = subfsMap.get(fullPath); 226 234 227 235 if (subfsEntries) { 228 - console.log(`Merging subfs node at ${fullPath} (${subfsEntries.length} entries, flat: ${isFlat})`); 236 + console.log(`[Depth ${depth}] Merging subfs node at ${fullPath} (${subfsEntries.length} entries, flat: ${isFlat})`); 229 237 230 238 if (isFlat) { 231 239 // Flat merge: hoist entries directly into parent directory ··· 265 273 return result; 266 274 } 267 275 268 - return { 276 + const partiallyExpanded = { 269 277 ...directory, 270 278 entries: replaceSubfsInEntries(directory.entries) 271 279 }; 280 + 281 + // Recursively expand any remaining subfs nodes (e.g., nested subfs inside parent subfs) 282 + return expandSubfsNodes(partiallyExpanded, pdsEndpoint, depth + 1); 272 283 } 273 284 274 285