Optimize checkVersion,feed code (#1605)
This commit is contained in:
@@ -353,7 +353,7 @@ class Client
|
||||
* 获取回执的头部信息
|
||||
*
|
||||
* @param string $key 头信息名称
|
||||
* @return string
|
||||
* @return ?string
|
||||
*/
|
||||
public function getResponseHeader(string $key): ?string
|
||||
{
|
||||
|
||||
+4
-9
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user