show errors when search failed;
This commit is contained in:
@@ -19,6 +19,9 @@ class TPB extends searchBase implements searchInterface
|
||||
$this->searchUrl = $this->baseUrl . trim($keyword);
|
||||
$this->crawler->add($this->getContent());
|
||||
$this->getItems()->addActionLinks(null);
|
||||
if ($this->hasErrors()) {
|
||||
return ['error' => $this->getErrors()];
|
||||
}
|
||||
return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
|
||||
}
|
||||
public function setContent($content)
|
||||
@@ -30,8 +33,15 @@ class TPB extends searchBase implements searchInterface
|
||||
if ($this->content) {
|
||||
return $this->content;
|
||||
}
|
||||
$content;
|
||||
try {
|
||||
$response = $this->client->request('GET', $this->searchUrl);
|
||||
return $response->getContent();
|
||||
$content = $response->getContent();
|
||||
} catch (\Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
return [];
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
public function parse()
|
||||
{
|
||||
|
||||
@@ -20,7 +20,11 @@ class bitSearch extends searchBase implements searchInterface
|
||||
{
|
||||
$this->query = ['q' => trim($keyword), 'sort' => 'seeders'];
|
||||
$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);
|
||||
return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
|
||||
}
|
||||
@@ -33,8 +37,15 @@ class bitSearch extends searchBase implements searchInterface
|
||||
if ($this->content) {
|
||||
return $this->content;
|
||||
}
|
||||
$content;
|
||||
try {
|
||||
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
|
||||
return $response->getContent();
|
||||
$content = $response->getContent();
|
||||
} catch (\Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
return [];
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function parse()
|
||||
|
||||
@@ -7,6 +7,7 @@ abstract class searchBase
|
||||
protected $query = null;
|
||||
protected $tableTitles = [];
|
||||
protected $rows = [];
|
||||
protected $errors = [];
|
||||
protected $actionLinks = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']];
|
||||
|
||||
public function getTableTitles(): array
|
||||
@@ -38,4 +39,14 @@ abstract class searchBase
|
||||
return $this->rows;
|
||||
}
|
||||
|
||||
public function hasErrors(): bool
|
||||
{
|
||||
return (bool) (count($this->errors) > 0);
|
||||
}
|
||||
|
||||
public function getErrors(): string
|
||||
{
|
||||
return implode(",", $this->errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\NCDownloader\Search\Sites;
|
||||
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
|
||||
//slider.kz
|
||||
class sliderkz extends searchBase
|
||||
class sliderkz extends searchBase implements searchInterface
|
||||
{
|
||||
public $baseUrl = "https://slider.kz/vk_auth.php";
|
||||
protected $query = null;
|
||||
protected $tableTitles = [];
|
||||
|
||||
public function __construct($client)
|
||||
{
|
||||
$this->client = $client;
|
||||
@@ -19,6 +19,9 @@ class sliderkz extends searchBase
|
||||
$this->query = ['q' => trim($keyword)];
|
||||
$this->searchUrl = $this->baseUrl;
|
||||
$this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks(null);
|
||||
if ($this->hasErrors()) {
|
||||
return ['error' => $this->getErrors()];
|
||||
}
|
||||
return ["title" => $this->getTableTitles(), 'row' => $this->getRows()];
|
||||
}
|
||||
|
||||
@@ -37,7 +40,7 @@ class sliderkz extends searchBase
|
||||
private function transformResp($data): array
|
||||
{
|
||||
$items = [];
|
||||
if (count($data) < 1) {
|
||||
if (count($data) < 1 || $this->hasErrors()) {
|
||||
return [];
|
||||
}
|
||||
foreach ($data as $item) {
|
||||
@@ -54,7 +57,8 @@ class sliderkz extends searchBase
|
||||
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
|
||||
$resp = $response->toArray();
|
||||
} catch (ExceptionInterface $e) {
|
||||
return ["error" => $e->getMessage()];
|
||||
$this->errors[] = $e->getMessage();
|
||||
return [];
|
||||
}
|
||||
if (isset($resp['audios'])) {
|
||||
return array_values($resp["audios"])[0];
|
||||
|
||||
@@ -96,6 +96,10 @@ export default {
|
||||
tableInst.rowClass = "table-row-search";
|
||||
tableInst.create();
|
||||
}
|
||||
if (data.error) {
|
||||
helper.resetSearch(vm);
|
||||
helper.error(data.error);
|
||||
}
|
||||
})
|
||||
.send();
|
||||
},
|
||||
|
||||
@@ -249,6 +249,10 @@ const helper = {
|
||||
},
|
||||
t: function (str) {
|
||||
return t("ncdownloader", str);
|
||||
},
|
||||
resetSearch: function (vm) {
|
||||
vm.$data.loading = 0;
|
||||
contentTable.getInstance([], []).clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user