Switch top to fyyd
All checks were successful
repod / nextcloud (push) Successful in 1m5s
repod / nodejs (push) Successful in 1m18s

This commit is contained in:
Michel Roux 2023-07-25 21:44:25 +02:00
parent f91c693115
commit 95bd71e0a4
4 changed files with 39 additions and 32 deletions

View File

@ -13,6 +13,6 @@ declare(strict_types=1);
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'top#index', 'url' => '/top/{limit}', 'verb' => 'GET']
['name' => 'top#index', 'url' => '/top/{count}', 'verb' => 'GET']
]
];

View File

@ -29,22 +29,27 @@ class TopController extends Controller
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index(int $limit = 10): JSONResponse {
if (!in_array($limit, [10, 25, 50])) {
return new JSONResponse(['Invalid limit, can be 10, 25 or 50.'], Http::STATUS_BAD_REQUEST);
public function index(int $count = 10): JSONResponse {
$userLang = 'en';
try {
$langClient = $this->clientService->newClient();
$langResponse = $langClient->get("https://api.fyyd.de/0.2/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'])) {
$userLang = $this->l10n->getUserLanguage($this->userSession->getUser());
$userLang = explode('_', $userLang);
$userLang = count($userLang) > 1 ? $userLang[1] : $userLang[0];
$userLang = in_array($userLang, $langJson['data']) ? $userLang : 'en';
}
} catch (Exception $e) {
}
try {
$lang = $this->l10n->getUserLanguage($this->userSession->getUser());
$lang = explode('_', $lang);
$lang = count($lang) > 1 ? $lang[1] : $lang[0];
$lang = $lang === 'en' ? 'us' : $lang;
$client = $this->clientService->newClient();
$response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json");
/** @var array $json */
$json = json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR);
return new JSONResponse($json, $response->getStatusCode());
$podcastClient = $this->clientService->newClient();
$podcastReponse = $podcastClient->get("https://api.fyyd.de/0.2/feature/podcast/hot?count={$count}&language={$userLang}");
$podcastJson = (array) json_decode((string) $podcastReponse->getBody(), true, flags: JSON_THROW_ON_ERROR);
return new JSONResponse($podcastJson, $podcastReponse->getStatusCode());
} catch (Exception $e) {
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}

View File

@ -2,24 +2,26 @@
<fragment>
<p class="more">
<span>{{ t('Discover') }}</span>
<NcButton v-if="showMore" @click="more">
{{ t('More') }}
</NcButton>
<NcSelect v-model="count"
class="select"
:components="{Deselect: {}}"
:options="[...Array(10).keys()].map(x=>(x+1)*10)"
@input="fetch" />
</p>
<p>
<NcLoadingIcon v-if="loading" />
<ul v-if="!loading" class="tops">
<li v-for="top in tops.feed.results" :key="top.id">
<img :src="top.artworkUrl100" :alt="top.artistName" :title="top.artistName">
<li v-for="top in tops" :key="top.id">
<img :src="top.imgURL" :alt="top.author" :title="top.author">
</li>
</ul>
<span class="caption">{{ t('Suggests by iTunes') }}</span>
<span class="caption">{{ t('Suggests by fyyd') }}</span>
</p>
</fragment>
</template>
<script>
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { NcLoadingIcon, NcSelect } from '@nextcloud/vue'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
@ -27,30 +29,26 @@ import { showError } from '@nextcloud/dialogs'
export default {
name: 'Top',
components: {
NcButton,
NcLoadingIcon,
NcSelect,
},
data() {
return {
tops: [],
loading: true,
showMore: true,
count: 10,
}
},
async mounted() {
await this.fetch(10)
await this.fetch()
},
methods: {
async more() {
this.showMore = false
await this.fetch(50)
},
async fetch(limit) {
async fetch() {
this.loading = true
try {
const top = await axios.get(generateUrl('/apps/repod/top/{limit}', { limit }))
this.tops = top.data
const top = await axios.get(generateUrl('/apps/repod/top/{count}', { count: this.count }))
this.tops = top.data.data
} catch (e) {
console.error(e)
showError(t('Could not fetch tops'))
@ -79,6 +77,10 @@ export default {
width: 100%;
}
.select {
min-width: 160px;
}
.more {
display: flex;
justify-content: space-between;

View File

@ -34,7 +34,7 @@ export default {
<style scoped>
.main {
margin: 11px 55px;
margin: 22px 55px;
display: flex;
flex-direction: column;
gap: 1rem;