MCPcopy Create free account
hub / github.com/3dugc/3D-Model-Optimizer / findModelFile

Function findModelFile

src/utils/model-input.ts:68–101  ·  view source on GitHub ↗
(dir: string, rootDir = dir, seen = { files: 0, bytes: 0 })

Source from the content-addressed store, hash-verified

66 throwIfAborted(signal);
67 const result = await execFileAsync('unzip', ['-Z', '-t', zipPath], { maxBuffer: 1024 * 1024, signal });
68 const match = result.stdout.match(/,\s*([0-9]+)\s+bytes uncompressed/i);
69 return match ? Number(match[1]) : undefined;
70}
71
72function findModelFile(dir: string, rootDir = dir, seen = { files: 0, bytes: 0 }): string | undefined {
73 const entries = fs.readdirSync(dir, { withFileTypes: true });
74
75 for (const entry of entries) {
76 const entryPath = path.join(dir, entry.name);
77 assertInside(rootDir, entryPath);
78 const stat = fs.lstatSync(entryPath);
79 if (stat.isSymbolicLink()) continue;
80 if (stat.isFile()) {
81 seen.files++;
82 seen.bytes += stat.size;
83 if (seen.files > MAX_ZIP_FILES || seen.bytes > MAX_ZIP_BYTES) {
84 throw new OptimizationError(ERROR_CODES.INVALID_FILE, 'ZIP archive exceeds safety limits.', {
85 maxFiles: MAX_ZIP_FILES,
86 maxBytes: MAX_ZIP_BYTES,
87 });
88 }
89 const ext = getFileExtension(entry.name);
90 if (MODEL_EXTENSIONS.has(ext)) return entryPath;
91 }
92 }
93
94 for (const entry of entries) {
95 const entryPath = path.join(dir, entry.name);
96 assertInside(rootDir, entryPath);
97 const stat = fs.lstatSync(entryPath);
98 if (stat.isDirectory() && !entry.name.startsWith('__')) {
99 const found = findModelFile(entryPath, rootDir, seen);
100 if (found) return found;
101 }
102 }
103
104 return undefined;

Callers 1

extractZipAndFindModelFunction · 0.85

Calls 3

getFileExtensionFunction · 0.90
assertInsideFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected