Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug in prior refactor #4179

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions actions/DisplayAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ private function createResponse(Request $request, BridgeAbstract $bridge, string
$input = array_diff_key($requestArray, array_fill_keys($remove, ''));
$bridge->setInput($input);
$bridge->collectData();
$items = $bridge->getItems();
if (isset($items[0]) && is_array($items[0])) {
$feedItems = [];
foreach ($items as $item) {
$feedItems[] = FeedItem::fromArray($item);
}
$items = $feedItems;
}
$feed = $bridge->getFeed();
} catch (\Exception $e) {
// Probably an exception inside a bridge
if ($e instanceof HttpException) {
Expand Down Expand Up @@ -145,16 +154,6 @@ private function createResponse(Request $request, BridgeAbstract $bridge, string
}
}

$items = $bridge->getItems();
if (isset($items[0]) && is_array($items[0])) {
$feedItems = [];
foreach ($items as $item) {
$feedItems[] = FeedItem::fromArray($item);
}
$items = $feedItems;
}
$feed = $bridge->getFeed();

$formatFactory = new FormatFactory();
$format = $formatFactory->create($format);

Expand Down
18 changes: 8 additions & 10 deletions bridges/GelbooruBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getFullURI()
return $this->getURI()
. 'index.php?&page=dapi&s=post&q=index&json=1&pid=' . $this->getInput('p')
. '&limit=' . $this->getInput('l')
. '&tags=' . urlencode($this->getInput('t'));
. '&tags=' . urlencode($this->getInput('t') ?? '');
}

/*
Expand Down Expand Up @@ -76,18 +76,16 @@ protected function getItemFromElement($element)

public function collectData()
{
$content = getContents($this->getFullURI());
// $content is empty string
$url = $this->getFullURI();
$content = getContents($url);

// Most other Gelbooru-based boorus put their content in the root of
// the JSON. This check is here for Bridges that inherit from this one
$posts = json_decode($content);
if (isset($posts->post)) {
$posts = $posts->post;
if ($content === '') {
return;
}

if (is_null($posts)) {
returnServerError('No posts found.');
$posts = Json::decode($content, false);
if (isset($posts->post)) {
$posts = $posts->post;
}

foreach ($posts as $post) {
Expand Down
Loading