From 04519388ce1bf3acc9997b35748762a7380e5954 Mon Sep 17 00:00:00 2001 From: skiingwiz Date: Sat, 27 Mar 2021 22:15:10 -0400 Subject: Allow directly adding a feed without going through the discovery process Signed-off-by: skiingwiz --- CHANGELOG.md | 1 + js/controller/NavigationController.js | 5 ++++- js/service/FeedResource.js | 5 +++-- js/tests/unit/controller/NavigationControllerSpec.js | 4 ++-- lib/Controller/FeedController.php | 6 ++++-- lib/Service/FeedServiceV2.php | 11 +++++++---- templates/part.navigation.addfeed.php | 7 +++++++ 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f3de31b5..d97cc5458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 - Make PHPStan stricter - Restore search in news - Improve test coverage +- Allow directly adding a feed without going through the discovery process (#1265) ### Fixed - Do not show deleted feeds in item list diff --git a/js/controller/NavigationController.js b/js/controller/NavigationController.js index 1b183cbdf..68a46900e 100644 --- a/js/controller/NavigationController.js +++ b/js/controller/NavigationController.js @@ -210,7 +210,9 @@ app.controller('NavigationController', function ($route, FEED_TYPE, FeedResource feed.url += regResult[2]; } - FeedResource.create(feed.url, existingFolder.id, undefined, feed.user, feed.password).then(function (data) { + var autoDiscover = feed.autoDiscover ? true : false; + FeedResource.create(feed.url, existingFolder.id, undefined, feed.user, feed.password, autoDiscover) + .then(function (data) { Publisher.publishAll(data); // set folder as default @@ -220,6 +222,7 @@ app.controller('NavigationController', function ($route, FEED_TYPE, FeedResource feed.url = ''; feed.user = ''; feed.password = ''; + feed.autoDiscover = true; self.addingFeed = false; }); diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js index 0ae7d2ad4..275bb1936 100644 --- a/js/service/FeedResource.js +++ b/js/service/FeedResource.js @@ -163,7 +163,7 @@ app.factory('FeedResource', function (Resource, $http, BASE_URL, $q) { }; - FeedResource.prototype.create = function (url, folderId, title, user, password) { + FeedResource.prototype.create = function (url, folderId, title, user, password, fullDiscover) { url = url.trim(); if (!url.startsWith('http')) { url = 'https://' + url; @@ -191,7 +191,8 @@ app.factory('FeedResource', function (Resource, $http, BASE_URL, $q) { parentFolderId: folderId || 0, title: title, user: user || null, - password: password || null + password: password || null, + fullDiscover: fullDiscover } }).then(function (response) { return response.data; diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js index 8329348a7..17aee7e22 100644 --- a/js/tests/unit/controller/NavigationControllerSpec.js +++ b/js/tests/unit/controller/NavigationControllerSpec.js @@ -361,7 +361,7 @@ describe('NavigationController', function () { expect(ctrl.showNewFolder).toBe(false); expect(FeedResource.create).toHaveBeenCalledWith('test', 3, - undefined, undefined, undefined); + undefined, undefined, undefined, false); expect(Publisher.publishAll).toHaveBeenCalledWith({feeds: [{ id: 3, url: 'test', @@ -441,7 +441,7 @@ describe('NavigationController', function () { expect(ctrl.showNewFolder).toBe(false); expect(FeedResource.create).toHaveBeenCalledWith('test', 19, - undefined, 'user', 'password'); + undefined, 'user', 'password', false); expect(FolderResource.create).toHaveBeenCalledWith('john'); expect(Publisher.publishAll).toHaveBeenCalledWith({ folders: [{ diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index 9c97d34b1..f071ade0f 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -161,7 +161,8 @@ class FeedController extends Controller ?int $parentFolderId, ?string $title = null, ?string $user = null, - ?string $password = null + ?string $password = null, + bool $fullDiscover = true ) { if ($parentFolderId === 0) { $parentFolderId = null; @@ -178,7 +179,8 @@ class FeedController extends Controller false, $title, $user, - $password + $password, + $fullDiscover ); $params = ['feeds' => [$feed]]; diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php index d15dfceb7..bb1be8dcb 100644 --- a/lib/Service/FeedServiceV2.php +++ b/lib/Service/FeedServiceV2.php @@ -189,15 +189,18 @@ class FeedServiceV2 extends Service bool $full_text = false, ?string $title = null, ?string $user = null, - ?string $password = null + ?string $password = null, + bool $full_discover = true ): Entity { if ($this->existsForUser($userId, $feedUrl)) { throw new ServiceConflictException('Feed with this URL exists'); } - $feeds = $this->explorer->discover($feedUrl); - if ($feeds !== []) { - $feedUrl = array_shift($feeds); + if ($full_discover) { + $feeds = $this->explorer->discover($feedUrl); + if ($feeds !== []) { + $feedUrl = array_shift($feeds); + } } try { diff --git a/templates/part.navigation.addfeed.php b/templates/part.navigation.addfeed.php index 595b1a1b4..6c198628c 100644 --- a/templates/part.navigation.addfeed.php +++ b/templates/part.navigation.addfeed.php @@ -9,6 +9,7 @@
+ + +