diff options
author | Benjamin Brahmer <info@b-brahmer.de> | 2022-08-08 19:23:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-08 19:23:42 +0200 |
commit | d4450ebad2385058467580620272fc020f7dc3db (patch) | |
tree | 3ce5ef91cdd1ab800c5d2238755939cb8e0edaa0 /lib | |
parent | 496084d44733879750a1ac017577e225ded07393 (diff) |
Change Autodiscover behaviour (#1860)
* change autodiscover behaviour to only run if the provided url is not already a feed
* Execute feed check after the final url is found
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Co-authored-by: Sean Molenaar <SMillerDev@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/FeedServiceV2.php | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php index bb1be8dcb..3e02b3971 100644 --- a/lib/Service/FeedServiceV2.php +++ b/lib/Service/FeedServiceV2.php @@ -192,17 +192,6 @@ class FeedServiceV2 extends Service ?string $password = null, bool $full_discover = true ): Entity { - if ($this->existsForUser($userId, $feedUrl)) { - throw new ServiceConflictException('Feed with this URL exists'); - } - - if ($full_discover) { - $feeds = $this->explorer->discover($feedUrl); - if ($feeds !== []) { - $feedUrl = array_shift($feeds); - } - } - try { /** * @var Feed $feed @@ -211,9 +200,25 @@ class FeedServiceV2 extends Service list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password); } catch (ReadErrorException $ex) { $this->logger->debug($ex->getMessage()); - throw new ServiceNotFoundException($ex->getMessage()); + if ($full_discover === false) { + throw new ServiceNotFoundException($ex->getMessage()); + } + $this->logger->warning("No valid feed found at URL, attempting auto discovery"); + $feeds = $this->explorer->discover($feedUrl); + if ($feeds !== []) { + $feedUrl = array_shift($feeds); + } + try { + list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password); + } catch (ReadErrorException $ex) { + throw new ServiceNotFoundException($ex->getMessage()); + } } + if ($this->existsForUser($userId, $feedUrl)) { + throw new ServiceConflictException('Feed with this URL exists'); + } + if ($feed === null) { throw new ServiceNotFoundException('Failed to fetch feed'); } |