show errors when search failed;

This commit is contained in:
huangjx
2022-02-27 14:28:56 +08:00
parent f9169240de
commit 3ff0f786f3
6 changed files with 55 additions and 11 deletions

View File

@@ -19,6 +19,9 @@ class TPB extends searchBase implements searchInterface
$this->searchUrl = $this->baseUrl . trim($keyword); $this->searchUrl = $this->baseUrl . trim($keyword);
$this->crawler->add($this->getContent()); $this->crawler->add($this->getContent());
$this->getItems()->addActionLinks(null); $this->getItems()->addActionLinks(null);
if ($this->hasErrors()) {
return ['error' => $this->getErrors()];
}
return ['title' => $this->getTableTitles(), 'row' => $this->getRows()]; return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
} }
public function setContent($content) public function setContent($content)
@@ -30,8 +33,15 @@ class TPB extends searchBase implements searchInterface
if ($this->content) { if ($this->content) {
return $this->content; return $this->content;
} }
$response = $this->client->request('GET', $this->searchUrl); $content;
return $response->getContent(); try {
$response = $this->client->request('GET', $this->searchUrl);
$content = $response->getContent();
} catch (\Exception $e) {
$this->errors[] = $e->getMessage();
return [];
}
return $content;
} }
public function parse() public function parse()
{ {

View File

@@ -20,9 +20,13 @@ class bitSearch extends searchBase implements searchInterface
{ {
$this->query = ['q' => trim($keyword), 'sort' => 'seeders']; $this->query = ['q' => trim($keyword), 'sort' => 'seeders'];
$this->searchUrl = $this->baseUrl; $this->searchUrl = $this->baseUrl;
$this->crawler->add($this->getContent()); $content = $this->getContent();
if ($this->hasErrors()) {
return ['error' => $this->getErrors()];
}
$this->crawler->add($content);
$this->getItems()->addActionLinks(null); $this->getItems()->addActionLinks(null);
return ['title' =>$this->getTableTitles(), 'row' => $this->getRows()]; return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
} }
public function setContent($content) public function setContent($content)
{ {
@@ -33,8 +37,15 @@ class bitSearch extends searchBase implements searchInterface
if ($this->content) { if ($this->content) {
return $this->content; return $this->content;
} }
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]); $content;
return $response->getContent(); try {
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
$content = $response->getContent();
} catch (\Exception $e) {
$this->errors[] = $e->getMessage();
return [];
}
return $content;
} }
public function parse() public function parse()

View File

@@ -7,6 +7,7 @@ abstract class searchBase
protected $query = null; protected $query = null;
protected $tableTitles = []; protected $tableTitles = [];
protected $rows = []; protected $rows = [];
protected $errors = [];
protected $actionLinks = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']]; protected $actionLinks = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']];
public function getTableTitles(): array public function getTableTitles(): array
@@ -38,4 +39,14 @@ abstract class searchBase
return $this->rows; return $this->rows;
} }
public function hasErrors(): bool
{
return (bool) (count($this->errors) > 0);
}
public function getErrors(): string
{
return implode(",", $this->errors);
}
} }

View File

@@ -1,15 +1,15 @@
<?php <?php
namespace OCA\NCDownloader\Search\Sites; namespace OCA\NCDownloader\Search\Sites;
use OCA\NCDownloader\Tools\Helper; use OCA\NCDownloader\Tools\Helper;
//slider.kz //slider.kz
class sliderkz extends searchBase class sliderkz extends searchBase implements searchInterface
{ {
public $baseUrl = "https://slider.kz/vk_auth.php"; public $baseUrl = "https://slider.kz/vk_auth.php";
protected $query = null; protected $query = null;
protected $tableTitles = []; protected $tableTitles = [];
public function __construct($client) public function __construct($client)
{ {
$this->client = $client; $this->client = $client;
@@ -19,6 +19,9 @@ class sliderkz extends searchBase
$this->query = ['q' => trim($keyword)]; $this->query = ['q' => trim($keyword)];
$this->searchUrl = $this->baseUrl; $this->searchUrl = $this->baseUrl;
$this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks(null); $this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks(null);
if ($this->hasErrors()) {
return ['error' => $this->getErrors()];
}
return ["title" => $this->getTableTitles(), 'row' => $this->getRows()]; return ["title" => $this->getTableTitles(), 'row' => $this->getRows()];
} }
@@ -37,7 +40,7 @@ class sliderkz extends searchBase
private function transformResp($data): array private function transformResp($data): array
{ {
$items = []; $items = [];
if (count($data) < 1) { if (count($data) < 1 || $this->hasErrors()) {
return []; return [];
} }
foreach ($data as $item) { foreach ($data as $item) {
@@ -54,7 +57,8 @@ class sliderkz extends searchBase
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]); $response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
$resp = $response->toArray(); $resp = $response->toArray();
} catch (ExceptionInterface $e) { } catch (ExceptionInterface $e) {
return ["error" => $e->getMessage()]; $this->errors[] = $e->getMessage();
return [];
} }
if (isset($resp['audios'])) { if (isset($resp['audios'])) {
return array_values($resp["audios"])[0]; return array_values($resp["audios"])[0];

View File

@@ -96,6 +96,10 @@ export default {
tableInst.rowClass = "table-row-search"; tableInst.rowClass = "table-row-search";
tableInst.create(); tableInst.create();
} }
if (data.error) {
helper.resetSearch(vm);
helper.error(data.error);
}
}) })
.send(); .send();
}, },

View File

@@ -248,7 +248,11 @@ const helper = {
} }
}, },
t: function (str) { t: function (str) {
return t("ncdownloader", str); return t("ncdownloader", str);
},
resetSearch: function (vm) {
vm.$data.loading = 0;
contentTable.getInstance([], []).clear();
} }
} }