getMessage(); $status = $exception->httpStatus; } catch (\Throwable $exception) { error_log('Object storage settings read failed: ' . get_class($exception)); $error = '对象存储配置暂时无法读取,请检查数据库状态。'; $status = 503; } $smarty = $this->view()->assign([ 'object_storage' => $state, 'object_storage_error' => $error, ]); $response->getBody()->write($smarty->fetch('admin/object_storage.tpl')); return $response->withStatus($status) ->withHeader('Cache-Control', 'private, no-store'); } public function save($request, $response, $args) { try { $state = CloudObjectStorageConfig::save(CloudInput::object($request)); return $this->json($response, 1, '对象存储配置已保存,请执行连接验证。', 200, $state); } catch (CloudError $exception) { return $this->json($response, 0, $exception->getMessage(), $exception->httpStatus); } catch (\Throwable $exception) { error_log('Object storage settings save failed: ' . get_class($exception)); return $this->json($response, 0, '对象存储配置保存失败,请稍后重试。', 500); } } public function test($request, $response, $args) { try { $input = CloudInput::object($request); CloudInput::only($input, ['expected_revision']); $state = CloudObjectStorageConfig::testAndEnable( $input['expected_revision'] ?? null ); return $this->json($response, 1, '连接验证成功,对象存储已启用。', 200, $state); } catch (CloudError $exception) { return $this->json($response, 0, $exception->getMessage(), $exception->httpStatus); } catch (\Throwable $exception) { error_log('Object storage connection test failed: ' . get_class($exception)); return $this->json($response, 0, '连接验证失败,请稍后重试。', 500); } } public function disable($request, $response, $args) { try { $input = CloudInput::object($request); CloudInput::only($input, ['expected_revision']); $state = CloudObjectStorageConfig::disable( $input['expected_revision'] ?? null ); return $this->json($response, 1, '对象存储已停用,已保存的凭据仍保持加密。', 200, $state); } catch (CloudError $exception) { return $this->json($response, 0, $exception->getMessage(), $exception->httpStatus); } catch (\Throwable $exception) { error_log('Object storage disable failed: ' . get_class($exception)); return $this->json($response, 0, '对象存储停用失败,请稍后重试。', 500); } } /** @param array|null $state */ private function json($response, int $ret, string $message, int $status, ?array $state = null) { $payload = ['ret' => $ret, 'msg' => $message]; if ($state !== null) { $payload['object_storage'] = $state; } return $response->withJson($payload, $status) ->withHeader('Cache-Control', 'private, no-store'); } }