Optimize checkVersion,feed code (#1605)

This commit is contained in:
Lu Fei
2023-09-22 10:49:51 +08:00
committed by GitHub
parent 666619538a
commit 9910a9cddc
2 changed files with 5 additions and 10 deletions
+1 -1
View File
@@ -353,7 +353,7 @@ class Client
* 获取回执的头部信息
*
* @param string $key 头信息名称
* @return string
* @return ?string
*/
public function getResponseHeader(string $key): ?string
{
+4 -9
View File
@@ -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);
}
/**