MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / createFileStructure

Function createFileStructure

src/utils/helpers.js:394–513  ·  view source on GitHub ↗
(uri, pathString, isFile = true)

Source from the content-addressed store, hash-verified

392 return Array.from(children);
393 },
394 async createFileStructure(uri, pathString, isFile = true) {
395 const parts = pathString.split("/").filter(Boolean);
396 let currentUri = uri;
397
398 // Determine if it's a special case URI
399 const isSpecialCase = currentUri.includes("::");
400 let baseFolder;
401 const isExternalStorageUri = currentUri.includes(
402 "com.android.externalstorage.documents",
403 );
404 const isTermuxUri = currentUri.includes("com.termux.documents");
405 const isAcodeTerminalPublicSafUri = currentUri.includes(
406 "com.foxdebug.acode.documents",
407 );
408 const [, treeSegment = ""] = currentUri.split("/tree/");
409 const terminalBasePath = isAcodeTerminalPublicSafUri
410 ? decodeURIComponent(treeSegment.split("::")[0] || "")
411 : "";
412 const getTargetUri = (baseUri, name, index) => {
413 if (
414 !(isExternalStorageUri || isTermuxUri || isAcodeTerminalPublicSafUri)
415 ) {
416 return Url.join(baseUri, name);
417 }
418
419 let fullUri = baseUri;
420 if (isExternalStorageUri) {
421 if (!isSpecialCase && index === 0) {
422 fullUri += `::primary:${baseFolder}/${name}`;
423 } else {
424 fullUri += `/${name}`;
425 }
426 } else if (isTermuxUri) {
427 if (!isSpecialCase && index === 0) {
428 fullUri += `::/data/data/com.termux/files/home/${name}`;
429 } else {
430 fullUri += `/${name}`;
431 }
432 } else if (isAcodeTerminalPublicSafUri) {
433 if (!isSpecialCase && index === 0) {
434 const sanitizedBase = terminalBasePath.endsWith("/")
435 ? `${terminalBasePath}${name}`
436 : `${terminalBasePath}/${name}`;
437 fullUri += `::${sanitizedBase}`;
438 } else {
439 fullUri += `/${name}`;
440 }
441 }
442 return fullUri;
443 };
444 const getExpectedType = (isLastPart) =>
445 isLastPart && isFile ? "file" : "folder";
446 const ensureEntry = async (baseUri, targetUri, name, expectedType) => {
447 const entries = await fsOperation(baseUri).lsDir();
448 const existingEntry = entries.find((entry) => entry.name === name);
449
450 if (existingEntry) {
451 const actualType = existingEntry.isDirectory ? "folder" : "file";

Callers

nothing calls this directly

Calls 3

getTargetUriFunction · 0.85
getExpectedTypeFunction · 0.85
ensureEntryFunction · 0.85

Tested by

no test coverage detected