Update pihole module

This commit is contained in:
2026-03-09 01:44:57 +01:00
parent c77b4b3ea7
commit 4adb50dc57
3 changed files with 94 additions and 24 deletions

View File

@@ -97,10 +97,26 @@ $apiRequest = function (array $instance, array $params) use ($normalizeApiPath):
return ['ok' => true, 'data' => $data, 'http_code' => $httpCode, 'url' => $full];
};
$pickInstances = function (string $target) use ($instances): array {
$resolvePrimaryId = function () use ($instances): ?string {
foreach ($instances as $id => $row) {
if (!empty($row['is_primary'])) {
return $id;
}
}
$first = array_key_first($instances);
return $first !== null ? (string)$first : null;
};
$pickInstances = function (string $target) use ($instances, $resolvePrimaryId): array {
if ($target === 'all') {
return $instances;
}
if ($target === 'primary') {
$primaryId = $resolvePrimaryId();
if ($primaryId !== null && isset($instances[$primaryId])) {
return [$primaryId => $instances[$primaryId]];
}
}
if (isset($instances[$target])) {
return [$target => $instances[$target]];
}