header('X-Sync-Token') === $token; } public function export(Request $request): JsonResponse { if (! $this->verifyToken($request)) { return response()->json(['error' => 'Unauthorized'], 401); } $since = (int) $request->query('since', 0); return response()->json([ 'last_sync_id' => SyncLog::lastSyncId(), 'changes' => SyncLog::changesSince($since), ]); } public function apply(Request $request): JsonResponse { if (! $this->verifyToken($request)) { return response()->json(['error' => 'Unauthorized'], 401); } set_time_limit(0); $service = SyncService::fromConfig(); $report = $service->applyChanges($request->input('changes', [])); return response()->json(['report' => $report]); } public function downloadFile(Request $request): mixed { if (! $this->verifyToken($request)) { return response()->json(['error' => 'Unauthorized'], 401); } $path = $request->query('path'); if (! $path || ! Storage::disk('public')->exists($path)) { return response()->json(['error' => 'File not found'], 404); } return Storage::disk('public')->download($path); } public function receiveFile(Request $request): JsonResponse { if (! $this->verifyToken($request)) { return response()->json(['error' => 'Unauthorized'], 401); } set_time_limit(0); $path = $request->input('path'); $file = $request->file('file'); if (! $path || ! $file) { return response()->json(['error' => 'Missing path or file'], 400); } $path = ltrim(str_replace(['..', '\\'], ['', '/'], $path), '/'); Storage::disk('public')->put($path, file_get_contents($file->getRealPath())); return response()->json(['success' => true, 'path' => $path]); } }