getAttribute('cloud_actor') ?? CloudAccess::actor(); if (!($actor['is_admin'] ?? false)) { throw new CloudError('需要管理员权限', 403); } if ($write) { CloudAccess::manage($actor); } return $actor; } public function index($request, $response, $args) { $write = strtoupper((string) $request->getMethod()) === 'POST'; $actor = $this->actor($request, $write); $hostId = (int) ($args['id'] ?? 0); $sourcePoolKey = (string) ($args['pool_key'] ?? ''); if (!$write) { $result = CloudPublicIpPoolReplacementBatchService::overview( $hostId, $sourcePoolKey, $actor ); return $response->withJson($result) ->withHeader('Cache-Control', 'private, no-store'); } $body = CloudInput::object($request); CloudInput::only($body, [ 'target_pool_key', 'expected_source_revision', 'expected_target_revision', 'request_key', 'confirm_replacement', ]); $result = CloudPublicIpPoolReplacementBatchService::start( $hostId, $sourcePoolKey, $actor, $body ); $job = $result['job']; return $response->withJson([ 'task_id' => (string) $job->id, 'status_url' => '/api/v1/tasks/' . (int) $job->id, 'batch_key' => (string) ($result['batch']['batch_key'] ?? ''), 'batch' => $result['batch'], 'unchanged' => ($result['unchanged'] ?? false) === true, ], 202)->withHeader('Cache-Control', 'no-store'); } public function detail($request, $response, $args) { $actor = $this->actor($request, false); $result = CloudPublicIpPoolReplacementBatchService::detail( (int) ($args['id'] ?? 0), (string) ($args['pool_key'] ?? ''), (string) ($args['batch_key'] ?? ''), $actor ); return $response->withJson($result) ->withHeader('Cache-Control', 'private, no-store'); } }