diff --git a/var/Typecho/Http/Client.php b/var/Typecho/Http/Client.php index 3c876b36..ba08298f 100644 --- a/var/Typecho/Http/Client.php +++ b/var/Typecho/Http/Client.php @@ -353,7 +353,7 @@ class Client * 获取回执的头部信息 * * @param string $key 头信息名称 - * @return string + * @return ?string */ public function getResponseHeader(string $key): ?string { diff --git a/var/Widget/Ajax.php b/var/Widget/Ajax.php index ab064398..3c01c9fd 100644 --- a/var/Widget/Ajax.php +++ b/var/Widget/Ajax.php @@ -41,10 +41,10 @@ class Ajax extends BaseOptions implements ActionInterface { $this->user->pass('editor'); $client = Client::get(); + $result = ['available' => 0]; if ($client) { $client->setHeader('User-Agent', $this->options->generator) ->setTimeout(10); - $result = ['available' => 0]; try { $client->send('https://typecho.org/version.json'); @@ -72,11 +72,9 @@ class Ajax extends BaseOptions implements ActionInterface } catch (\Exception $e) { // do nothing } - - $this->response->throwJson($result); } - throw new Exception(_t('禁止访问'), 403); + $this->response->throwJson($result); } /** @@ -89,6 +87,7 @@ class Ajax extends BaseOptions implements ActionInterface { $this->user->pass('subscriber'); $client = Client::get(); + $data = []; if ($client) { $client->setHeader('User-Agent', $this->options->generator) ->setTimeout(10) @@ -102,8 +101,6 @@ class Ajax extends BaseOptions implements ActionInterface $matches ); - $data = []; - if ($matches) { foreach ($matches[0] as $key => $val) { $data[] = [ @@ -117,11 +114,9 @@ class Ajax extends BaseOptions implements ActionInterface } } } - - $this->response->throwJson($data); } - throw new Exception(_t('禁止访问'), 403); + $this->response->throwJson($data); } /**