Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions public/api/projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,31 @@ function listProjects($basePath) {
return $projects;
}

$dirs = scandir($basePath);
foreach ($dirs as $dir) {
if ($dir === '.' || $dir === '..') continue;
// ⚑ Bolt: Replace scandir() with FilesystemIterator to reduce memory footprint via lazy iteration over large directories
$iterator = new FilesystemIterator($basePath, FilesystemIterator::SKIP_DOTS);

foreach ($iterator as $fileInfo) {
if (!$fileInfo->isDir()) continue;

$fullPath = $basePath . '/' . $dir;
if (!is_dir($fullPath)) continue;
$dir = $fileInfo->getFilename();
$fullPath = str_replace('\\', '/', $fileInfo->getPathname());

// Skip hidden directories and common non-project dirs
if (strpos($dir, '.') === 0) continue;
if (in_array($dir, ['node_modules', 'vendor', '__pycache__', '.git'])) continue;

$modified = date('Y-m-d H:i'); // Fallback
try {
$modified = date('Y-m-d H:i', $fileInfo->getMTime());
} catch (RuntimeException $e) {
// Ignore unreadable files or broken symlinks to prevent API crash
}

$projects[] = [
'name' => $dir,
'path' => $fullPath,
'type' => detectProjectType($fullPath),
'modified' => date('Y-m-d H:i', filemtime($fullPath)),
'modified' => $modified,
];
}

Expand Down