Refacto modal and fix double guid
Some checks failed
repod / xml (push) Successful in 20s
repod / php (push) Failing after 1m3s
repod / nodejs (push) Successful in 1m48s

This commit is contained in:
Michel Roux 2023-12-24 16:59:34 +01:00
parent d43ec9dd75
commit a4c4d3a2ce
5 changed files with 99 additions and 54 deletions

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace OCA\RePod\Controller;
use OCA\RePod\AppInfo\Application;
use OCA\RePod\Core\EpisodeAction\EpisodeActionExtraData;
use OCA\RePod\Core\EpisodeAction\EpisodeActionReader;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
@ -26,7 +27,12 @@ class EpisodesController extends Controller
$client = $this->clientService->newClient();
$feed = $client->get($url);
return new JSONResponse($this->episodeActionReader->parseRssXml((string) $feed->getBody()), $feed->getStatusCode());
$episodes = $this->episodeActionReader->parseRssXml((string) $feed->getBody());
usort($episodes, fn (EpisodeActionExtraData $a, EpisodeActionExtraData $b) => $b->getFetchedAtUnix() <=> $a->getFetchedAtUnix());
$episodes = array_intersect_key($episodes, array_unique(array_map(fn (EpisodeActionExtraData $episode) => $episode->getEpisodeGuid(), $episodes)));
return new JSONResponse($episodes, $feed->getStatusCode());
}
public function action(string $url): JSONResponse {

View File

@ -33,15 +33,10 @@ class PodcastController extends Controller
$client = $this->clientService->newClient();
$feed = $client->get($url);
$statusCode = $feed->getStatusCode();
if ($statusCode < 200 || $statusCode >= 300) {
throw new \ErrorException("Web request returned non-2xx status code: {$statusCode}");
}
$podcast = PodcastData::parseRssXml((string) $feed->getBody());
$this->podcastDataReader->trySetCachedPodcastData($url, $podcast);
return new JSONResponse($podcast, $statusCode);
return new JSONResponse($podcast, $feed->getStatusCode());
}
}

View File

@ -7,7 +7,6 @@ namespace OCA\RePod\Controller;
use OCA\RePod\AppInfo\Application;
use OCA\RePod\Service\FyydService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
@ -25,10 +24,6 @@ class ToplistController extends Controller
* @NoCSRFRequired
*/
public function index(): JSONResponse {
try {
return new JSONResponse($this->fyydService->hot());
} catch (\Exception $e) {
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new JSONResponse($this->fyydService->hot());
}
}

View File

@ -38,38 +38,21 @@
<NcModal v-if="modalEpisode"
size="small"
@close="modalEpisode = null">
<div class="modal-content">
<NcAvatar :display-name="modalEpisode.episodeName"
:is-no-user="true"
size="256"
:url="modalEpisode.episodeImage" />
<h2>{{ modalEpisode.episodeName }}</h2>
{{ modalEpisode.episodeDescription }}
<div class="modal-buttons">
<NcButton v-if="modalEpisode.episodeLink" :href="modalEpisode.episodeLink" target="_blank">
<template #icon>
<OpenInNew :size="20" />
</template>
{{ modalEpisode.podcastName }}
</NcButton>
<NcButton v-if="modalEpisode.episodeUrl" :href="modalEpisode.episodeUrl" target="_blank">
<template #icon>
<Download :size="20" />
</template>
{{ t('Download') }}
</NcButton>
</div>
</div>
<Modal :episode-description="modalEpisode.episodeDescription"
:episode-image="modalEpisode.episodeImage"
:episode-link="modalEpisode.episodeLink"
:episode-name="modalEpisode.episodeName"
:episode-url="modalEpisode.episodeUrl"
:podcast-name="modalEpisode.podcastName" />
</NcModal>
</div>
</template>
<script>
import { NcActionButton, NcAvatar, NcButton, NcListItem, NcModal } from '@nextcloud/vue'
import { NcActionButton, NcAvatar, NcListItem, NcModal } from '@nextcloud/vue'
import AdaptativeList from '../Atoms/AdaptativeList.vue'
import Download from 'vue-material-design-icons/Download.vue'
import Loading from '../Atoms/Loading.vue'
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
import Modal from './Modal.vue'
import PlayButton from 'vue-material-design-icons/Play.vue'
import StopButton from 'vue-material-design-icons/Stop.vue'
import axios from '@nextcloud/axios'
@ -82,14 +65,12 @@ export default {
name: 'Episodes',
components: {
AdaptativeList,
Download,
Loading,
Modal,
NcActionButton,
NcAvatar,
NcButton,
NcListItem,
NcModal,
OpenInNew,
PlayButton,
StopButton,
},
@ -137,17 +118,4 @@ export default {
.ended {
opacity: .5;
}
.modal-content {
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
margin: 2rem;
}
.modal-buttons {
display: flex;
gap: 1rem;
}
</style>

View File

@ -0,0 +1,81 @@
<template>
<div class="content">
<NcAvatar :display-name="episodeName"
:is-no-user="true"
size="256"
:url="episodeImage" />
<h2>{{ episodeName }}</h2>
{{ episodeDescription }}
<div class="buttons">
<NcButton v-if="episodeLink" :href="episodeLink" target="_blank">
<template #icon>
<OpenInNew :size="20" />
</template>
{{ podcastName }}
</NcButton>
<NcButton v-if="episodeUrl" :href="episodeUrl" target="_blank">
<template #icon>
<Download :size="20" />
</template>
{{ t('Download') }}
</NcButton>
</div>
</div>
</template>
<script>
import { NcAvatar, NcButton } from '@nextcloud/vue'
import Download from 'vue-material-design-icons/Download.vue'
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
export default {
name: 'Modal',
components: {
Download,
NcAvatar,
NcButton,
OpenInNew,
},
props: {
episodeName: {
type: String,
required: true,
},
episodeImage: {
type: String,
required: true,
},
episodeDescription: {
type: String,
required: true,
},
episodeUrl: {
type: String,
required: true,
},
episodeLink: {
type: String,
default: null,
},
podcastName: {
type: String,
required: true,
},
},
}
</script>
<style scoped>
.content {
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
margin: 2rem;
}
.buttons {
display: flex;
gap: 1rem;
}
</style>