diff --git a/appinfo/routes.php b/appinfo/routes.php index 138f1f6..34ef9b2 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -13,7 +13,8 @@ declare(strict_types=1); return [ 'routes' => [ ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], - ['name' => 'episodes#index', 'url' => '/episodes', 'verb' => 'GET'], + ['name' => 'episodes#action', 'url' => '/episodes/action', 'verb' => 'GET'], + ['name' => 'episodes#list', 'url' => '/episodes/list', 'verb' => 'GET'], ['name' => 'podcast#index', 'url' => '/podcast', 'verb' => 'GET'], ['name' => 'search#index', 'url' => '/search', 'verb' => 'GET'], ['name' => 'toplist#index', 'url' => '/toplist', 'verb' => 'GET'], diff --git a/lib/Controller/EpisodesController.php b/lib/Controller/EpisodesController.php index e0d18fb..ef9d585 100644 --- a/lib/Controller/EpisodesController.php +++ b/lib/Controller/EpisodesController.php @@ -4,9 +4,12 @@ declare(strict_types=1); namespace OCA\RePod\Controller; +use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository; use OCA\RePod\AppInfo\Application; use OCA\RePod\Core\EpisodeAction\EpisodeActionReader; +use OCA\RePod\Service\UserService; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\Http\Client\IClientService; use OCP\IRequest; @@ -16,16 +19,29 @@ class EpisodesController extends Controller public function __construct( IRequest $request, private IClientService $clientService, - private EpisodeActionReader $episodeActionReader + private EpisodeActionReader $episodeActionReader, + private EpisodeActionRepository $episodeActionRepository, + private UserService $userService ) { parent::__construct(Application::APP_ID, $request); } - public function index(string $url): JSONResponse + public function list(string $url): JSONResponse { $client = $this->clientService->newClient(); $feed = $client->get($url); return new JSONResponse($this->episodeActionReader->parseRssXml((string) $feed->getBody()), $feed->getStatusCode()); } + + public function action(string $url): JSONResponse + { + $action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID()); + + if ($action) { + return new JSONResponse($action->toArray()); + } + + return new JSONResponse([], Http::STATUS_NOT_FOUND); + } } diff --git a/lib/Core/EpisodeAction/EpisodeActionExtraData.php b/lib/Core/EpisodeAction/EpisodeActionExtraData.php index ed86c8b..a018927 100644 --- a/lib/Core/EpisodeAction/EpisodeActionExtraData.php +++ b/lib/Core/EpisodeAction/EpisodeActionExtraData.php @@ -22,8 +22,7 @@ use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction; * episodeGuid: string, * episodePubDate: ?\DateTime, * episodeFilesize: ?int, - * episodeDuration: ?int, - * episodeAction: ?EpisodeActionType + * episodeDuration: ?int * } */ class EpisodeActionExtraData implements \JsonSerializable @@ -39,8 +38,7 @@ class EpisodeActionExtraData implements \JsonSerializable private string $episodeGuid, private ?\DateTime $episodePubDate, private ?int $episodeFilesize, - private ?int $episodeDuration, - private ?EpisodeAction $episodeAction + private ?int $episodeDuration ) { $this->episodeUrl = $episodeUrl; $this->podcastName = $podcastName; @@ -53,7 +51,6 @@ class EpisodeActionExtraData implements \JsonSerializable $this->episodePubDate = $episodePubDate; $this->episodeFilesize = $episodeFilesize; $this->episodeDuration = $episodeDuration; - $this->episodeAction = $episodeAction; } public function __toString(): string @@ -81,11 +78,6 @@ class EpisodeActionExtraData implements \JsonSerializable return $this->episodeDuration; } - public function getEpisodeAction(): ?EpisodeAction - { - return $this->episodeAction; - } - public function getEpisodeUrl(): ?string { return $this->episodeUrl; @@ -109,7 +101,6 @@ class EpisodeActionExtraData implements \JsonSerializable 'episodePubDate' => $this->episodePubDate, 'episodeFilesize' => $this->episodeFilesize, 'episodeDuration' => $this->episodeDuration, - 'episodeAction' => $this->episodeAction ? $this->episodeAction->toArray() : null, ]; } diff --git a/lib/Core/EpisodeAction/EpisodeActionReader.php b/lib/Core/EpisodeAction/EpisodeActionReader.php index cbfb03a..8edee0a 100644 --- a/lib/Core/EpisodeAction/EpisodeActionReader.php +++ b/lib/Core/EpisodeAction/EpisodeActionReader.php @@ -4,18 +4,8 @@ declare(strict_types=1); namespace OCA\RePod\Core\EpisodeAction; -use OCA\GPodderSync\Core\EpisodeAction\EpisodeActionReader as GPodderSyncEpisodeActionReader; -use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository; -use OCA\RePod\Service\UserService; - -class EpisodeActionReader extends GPodderSyncEpisodeActionReader +class EpisodeActionReader { - public function __construct( - private EpisodeActionRepository $episodeActionRepository, - private UserService $userService - ) { - } - /** * https://github.com/pbek/nextcloud-nextpod/blob/main/lib/Core/EpisodeAction/EpisodeActionExtraData.php#L119. * @@ -46,9 +36,6 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader // Get episode filesize $episodeFilesize = (int) $item->enclosure['length']; - // Get episode action - $episodeAction = $this->episodeActionRepository->findByEpisodeUrl($episodeUrl, $this->userService->getUserUID()); - // Get episode name $episodeName = $this->stringOrNull($item->title); @@ -126,8 +113,7 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader $episodeGuid, $episodePubDate, $episodeFilesize, - $episodeDuration, - $episodeAction + $episodeDuration ); } diff --git a/src/components/Feed/List.vue b/src/components/Feed/List.vue index 5c518b2..310069f 100644 --- a/src/components/Feed/List.vue +++ b/src/components/Feed/List.vue @@ -66,7 +66,7 @@ export default { async mounted() { try { this.loading = true - const episodes = await axios.get(generateUrl('/apps/repod/episodes?url={url}', { url: this.url })) + const episodes = await axios.get(generateUrl('/apps/repod/episodes/list?url={url}', { url: this.url })) this.episodes = episodes.data } catch (e) { console.error(e) @@ -82,7 +82,7 @@ export default { return this.currentEpisode && this.currentEpisode.episodeUrl === episode.episodeUrl }, load(episode) { - this.$store.commit('player/load', episode) + this.$store.dispatch('player/load', episode) }, }, } diff --git a/src/store/player.js b/src/store/player.js index 68d02ad..4df7e3b 100644 --- a/src/store/player.js +++ b/src/store/player.js @@ -17,6 +17,7 @@ audio.onvolumechange = () => store.commit('player/volume', audio.volume) export const player = { namespaced: true, state: { + action: null, currentTime: null, duration: null, episode: null, @@ -26,13 +27,20 @@ export const player = { volume: null, }, mutations: { + action: (state, action) => { + state.action = action + + if (action && action.position) { + audio.currentTime = action.position + } + }, currentTime: (state, currentTime) => { state.currentTime = currentTime }, duration: (state, duration) => { state.duration = duration }, - load: (state, episode) => { + episode: (state, episode) => { state.episode = episode if (episode) { @@ -40,10 +48,6 @@ export const player = { audio.src = episode.episodeUrl audio.load() audio.play() - - if (episode.episodeAction) { - audio.currentTime = episode.episodeAction.position - } } else { state.loaded = false state.podcastUrl = null @@ -61,6 +65,11 @@ export const player = { }, }, actions: { + load: async (context, episode) => { + context.commit('episode', episode) + const action = await axios.get(generateUrl('/apps/repod/episodes/action?url={url}', { url: episode.episodeUrl })) + context.commit('action', action.data) + }, pause: (context) => { audio.pause() axios.post(generateUrl('/apps/gpoddersync/episode_action/create'), [{ @@ -69,7 +78,7 @@ export const player = { guid: context.state.episode.episodeGuid, action: 'play', timestamp: formatEpisodeTimestamp(new Date()), - started: Math.round(context.state.episode.episodeAction ? context.state.episode.episodeAction.started : 0), + started: Math.round(context.state.action ? context.state.action.started : 0), position: Math.round(audio.currentTime), total: Math.round(audio.duration), }]) @@ -80,7 +89,8 @@ export const player = { }, stop: (context) => { context.dispatch('pause') - context.commit('load', null) + context.commit('episode', null) + context.commit('action', null) }, volume: (context, volume) => { audio.volume = volume