diff --git a/appinfo/routes.php b/appinfo/routes.php index 7779d0f..eb63e71 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -16,6 +16,7 @@ return [ ['name' => 'episodes#action', 'url' => '/episodes/action', 'verb' => 'GET'], ['name' => 'episodes#list', 'url' => '/episodes/list', 'verb' => 'GET'], ['name' => 'opml#export', 'url' => '/opml/export', 'verb' => 'GET'], + ['name' => 'opml#import', 'url' => '/opml/import', 'verb' => 'POST'], ['name' => 'podcast#index', 'url' => '/podcast', 'verb' => 'GET'], ['name' => 'search#index', 'url' => '/search', 'verb' => 'GET'], ['name' => 'tops#hot', 'url' => '/tops/hot', 'verb' => 'GET'], diff --git a/lib/Controller/EpisodesController.php b/lib/Controller/EpisodesController.php index f292adc..8a47a6d 100644 --- a/lib/Controller/EpisodesController.php +++ b/lib/Controller/EpisodesController.php @@ -30,9 +30,7 @@ class EpisodesController extends Controller public function list(string $url): JSONResponse { $client = $this->clientService->newClient(); $feed = $client->get($url); - $episodes = $this->episodeActionReader->parseRssXml((string) $feed->getBody()); - usort($episodes, fn (EpisodeActionExtraData $a, EpisodeActionExtraData $b) => $b->getPubDate() <=> $a->getPubDate()); $episodes = array_values(array_intersect_key($episodes, array_unique(array_map(fn (EpisodeActionExtraData $episode) => $episode->getGuid(), $episodes)))); diff --git a/lib/Controller/OpmlController.php b/lib/Controller/OpmlController.php index ccb31fe..a8afd38 100644 --- a/lib/Controller/OpmlController.php +++ b/lib/Controller/OpmlController.php @@ -6,10 +6,12 @@ namespace OCA\RePod\Controller; use OCA\GPodderSync\Core\PodcastData\PodcastDataReader; use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader; +use OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChangeSaver; use OCA\RePod\AppInfo\Application; use OCA\RePod\Service\UserService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataDownloadResponse; +use OCP\AppFramework\Http\Response; use OCP\IL10N; use OCP\IRequest; @@ -20,6 +22,7 @@ class OpmlController extends Controller private IL10N $l10n, private PodcastDataReader $podcastDataReader, private PodcastMetricsReader $podcastMetricsReader, + private SubscriptionChangeSaver $subscriptionChangeSaver, private UserService $userService ) { parent::__construct(Application::APP_ID, $request); @@ -54,6 +57,8 @@ class OpmlController extends Controller $outline = $body->addChild('outline'); if (isset($outline)) { + $outline->addAttribute('xmlUrl', $subscription->getUrl()); + $title = $podcast->getTitle(); $link = $podcast->getLink(); @@ -63,7 +68,7 @@ class OpmlController extends Controller } if ($link) { - $outline->addAttribute('xmlUrl', $link); + $outline->addAttribute('htmlUrl', $link); } } } @@ -72,4 +77,28 @@ class OpmlController extends Controller return new DataDownloadResponse((string) $xml->asXML(), 'repod-'.$dateCreated->getTimestamp().'.opml', ' application/xml'); } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function import(): Response { + $file = $this->request->getUploadedFile('import'); + + if ($file) { + $xml = new \SimpleXMLElement(file_get_contents((string) $file['tmp_name'])); + + /** @var \SimpleXMLElement[] $outlines */ + $outlines = $xml->body->children(); + + $toSubscribe = []; + foreach ($outlines as $outline) { + $toSubscribe[] = (string) $outline['xmlUrl']; + } + + $this->subscriptionChangeSaver->saveSubscriptionChanges($toSubscribe, [], $this->userService->getUserUID()); + } + + return new Response(); + } } diff --git a/lib/Service/FyydService.php b/lib/Service/FyydService.php index f8caf73..c4258c2 100644 --- a/lib/Service/FyydService.php +++ b/lib/Service/FyydService.php @@ -86,6 +86,7 @@ class FyydService implements IPodProvider $langClient = $this->clientService->newClient(); $langResponse = $langClient->get(self::BASE_URL.'feature/podcast/hot/languages'); $langJson = (array) json_decode((string) $langResponse->getBody(), true, flags: JSON_THROW_ON_ERROR); + if (array_key_exists('data', $langJson) && is_array($langJson['data'])) { $language = in_array($userLang, $langJson['data']) ? $userLang : 'en'; } diff --git a/src/components/Sidebar/Settings.vue b/src/components/Sidebar/Settings.vue index e8199bb..9f30096 100644 --- a/src/components/Sidebar/Settings.vue +++ b/src/components/Sidebar/Settings.vue @@ -16,6 +16,31 @@ + + + + @@ -75,6 +123,13 @@ export default { gap: .5rem; } + .importModal { + align-items: center; + display: flex; + flex-direction: column; + margin: 2rem; + } + .pointer { cursor: pointer; }