Overworked files API and explorer

This commit is contained in:
2025-06-19 23:14:18 +02:00
parent c42d5a2652
commit de1664469c
15 changed files with 529 additions and 407 deletions

36
api/search.php Normal file
View File

@ -0,0 +1,36 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../vfs.php';
$dir = $_GET['dir'] ?? '';
$q = $_GET['q'] ?? '';
$showHidden = ($_GET['hidden'] ?? '0') === '1';
$base = resolve_path($dir);
if (!is_dir($base)) {
echo json_encode([]);
exit;
}
$out = [];
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($base, FilesystemIterator::SKIP_DOTS)
);
foreach ($it as $f) {
$name = $f->getFilename();
if (!$showHidden && strpos($name, '.') === 0) continue;
if (stripos($name, $q) === false) continue;
$full = $f->getPathname();
$out[] = [
'name' => $name,
'virtual' => virtualize_path($full),
'isDir' => $f->isDir(),
'ext' => $f->getExtension(),
'size' => $f->getSize(),
'mtime' => $f->getMTime(),
];
}
echo json_encode($out);