This commit is contained in:
Lars Behrends
2025-10-18 22:03:30 +02:00
parent f4c1cfc164
commit ca2d3a6960
45 changed files with 4827 additions and 326 deletions

View File

@@ -52,6 +52,26 @@ class AdminController extends Controller
return $response->withStatus(404)->withHeader('Content-Type', 'application/json');
}
// Validate sync type based on source type
if ($source['name'] === 'jellyfin') {
$validSyncTypes = ['full', 'incremental', 'all', 'movies', 'tvshows'];
if (!in_array($syncType, $validSyncTypes)) {
return $this->json($response, [
'success' => false,
'message' => 'Invalid sync type for Jellyfin source. Valid types: ' . implode(', ', $validSyncTypes)
], 400);
}
} else {
// For other sources, only allow full/incremental
$validSyncTypes = ['full', 'incremental'];
if (!in_array($syncType, $validSyncTypes)) {
return $this->json($response, [
'success' => false,
'message' => 'Invalid sync type. Valid types: ' . implode(', ', $validSyncTypes)
], 400);
}
}
// Start sync in background (simplified - in production you'd use queues)
$syncLogId = $this->startSync($source, $syncType);
@@ -77,7 +97,7 @@ class AdminController extends Controller
'id' => $syncLog['id'],
'status' => $syncLog['status'],
'sync_type' => $syncLog['sync_type'],
'total_items' => $syncLog['total_items'],
'total_items' => $syncLog['total_items'] ?? 0,
'processed_items' => $syncLog['processed_items'],
'new_items' => $syncLog['new_items'],
'updated_items' => $syncLog['updated_items'],
@@ -85,10 +105,20 @@ class AdminController extends Controller
'started_at' => $syncLog['started_at'],
'completed_at' => $syncLog['completed_at'],
'message' => $syncLog['message'],
'errors' => $syncLog['errors'] ? json_decode($syncLog['errors'], true) : []
'errors' => $syncLog['errors'] ? json_decode($syncLog['errors'], true) : [],
'progress_percentage' => $this->calculateProgressPercentage($syncLog)
]);
}
private function calculateProgressPercentage(array $syncLog): float
{
$total = $syncLog['total_items'] ?? 0;
if ($total <= 0) return 0;
$processed = $syncLog['processed_items'] ?? 0;
return min(100, round(($processed / $total) * 100, 2));
}
public function sources(Request $request, Response $response, $args)
{
$sourceModel = new Source($this->pdo);
@@ -116,11 +146,9 @@ class AdminController extends Controller
case 'adult':
$syncService = new AdultSyncService($this->pdo, $source);
break;
case 'exophase':
$syncService = new ExophaseSyncService($this->pdo, $source);
case 'xbvr':
$syncService = new XbvrSyncService($this->pdo, $source);
break;
default:
throw new \Exception('Unsupported source type: ' . $source['name']);
}
// Start sync (this would typically be queued in production)