diff --git a/Plugin/unraid/api/rsync.php b/Plugin/unraid/api/rsync.php index aab2627..bc74836 100644 --- a/Plugin/unraid/api/rsync.php +++ b/Plugin/unraid/api/rsync.php @@ -91,6 +91,38 @@ require_once dirname(__DIR__) . '/include/monitor.php'; // ── Live sync log ───────────────────────────────────────────────────────────── $action = $_GET['action'] ?? ''; +// ── Share list, for the quick-select strip on the window editor ────────────────────────────── +// The editor is path-first — type or browse, then Add — which is exact but slow for the case that +// is nearly all of them: add one whole share. This answers "what shares exist here", so the strip +// can offer them as one click each. +// +// Read from /boot/config/shares/*.cfg rather than by listing /mnt/user, because a share is a +// declared thing: the directory can be absent on a share that has never been written to, and +// listing the mount would also invent entries for stray directories that are not shares at all. +if ($action === 'shares') { + $out = []; + foreach (glob('/boot/config/shares/*.cfg') ?: [] as $cfg) { + $name = basename($cfg, '.cfg'); + $raw = (string) @file_get_contents($cfg); + $get = function (string $k) use ($raw): string { + return preg_match('/^' . $k . '="([^"]*)"/m', $raw, $m) ? $m[1] : ''; + }; + $path = '/mnt/user/' . $name; + $out[] = [ + 'name' => $name, + 'path' => $path, + 'comment' => $get('shareComment'), + 'pool' => $get('shareCachePool'), + 'cache' => $get('shareUseCache'), + // Present is not the same as declared — a share can exist in conf with no directory yet. + 'exists' => is_dir($path), + ]; + } + usort($out, fn($a, $b) => strcasecmp($a['name'], $b['name'])); + header('Content-Type: application/json'); + echo json_encode(['ok' => true, 'shares' => $out]); + exit; +} if ($action === 'rsync_log') { $lockDir = '/tmp/unraid_locks'; $lines = []; diff --git a/Plugin/unraid/pages/rsync.php b/Plugin/unraid/pages/rsync.php index 872dcb9..d249618 100644 --- a/Plugin/unraid/pages/rsync.php +++ b/Plugin/unraid/pages/rsync.php @@ -40,6 +40,19 @@ require_once dirname(__DIR__) . '/include/confui.php'; require_once dirname(__DIR__) . '/include/ai_chat.php'; ?>