MCPcopy Create free account
hub / github.com/massCodeIO/massCode / ensureFolder

Function ensureFolder

src/main/http/import/opencollection.ts:409–443  ·  view source on GitHub ↗
(
  collection: HttpImportCollection,
  folderIds: Map<string, string>,
  folderNames: Map<string, string>,
  path: string,
)

Source from the content-addressed store, hash-verified

407}
408
409function ensureFolder(
410 collection: HttpImportCollection,
411 folderIds: Map<string, string>,
412 folderNames: Map<string, string>,
413 path: string,
414): string | null {
415 const normalized = normalizePath(path)
416 if (!normalized)
417 return null
418
419 const segments = normalized.split('/').filter(Boolean)
420 let currentPath = ''
421 let parentId: string | null = null
422
423 for (const segment of segments) {
424 currentPath = currentPath ? `${currentPath}/${segment}` : segment
425 const existing = folderIds.get(currentPath)
426 if (existing) {
427 parentId = existing
428 continue
429 }
430
431 const id = currentPath
432 const folder: HttpImportFolder = {
433 id,
434 name: normalizeImportName(folderNames.get(currentPath), segment),
435 parentId,
436 }
437 folderIds.set(currentPath, id)
438 collection.folders.push(folder)
439 parentId = id
440 }
441
442 return parentId
443}
444
445function parseBundledItems(
446 items: unknown[],

Callers 1

parseOpenCollectionFilesFunction · 0.85

Calls 4

normalizeImportNameFunction · 0.90
normalizePathFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected