Skip to content

Commit

Permalink
fix: localhost api requests run into timeout
Browse files Browse the repository at this point in the history
this should fix #65

removed api request and switched to site and page methods
  • Loading branch information
mauricerenck committed Feb 27, 2024
1 parent 72b5f16 commit 844c73b
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 310 deletions.
10 changes: 10 additions & 0 deletions app/FeedMethods.php → app/PageMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@

return $this->podcasterCover()->toFile()->url();
},

'podloveRoles' => function () {
$podcast = new Podcast();
return $podcast->getPodloveRoles($this->slug());
},

'podloveGroups' => function () {
$podcast = new Podcast();
return $podcast->getPodloveGroups($this->slug());
},
];
44 changes: 38 additions & 6 deletions app/Podcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace mauricerenck\Podcaster;

use Exception;
use Kirby\Cms\Collection;
use Kirby\Cms\Structure;
use Kirby\Filesystem\F;
use Kirby\Toolkit\Str;
use Kirby\Http\Remote;

class Podcast
{
Expand Down Expand Up @@ -83,19 +86,19 @@ public function getAudioFile($episode)
return $episode->podcasterAudio()->toFile();
}

if(!is_null($episode->podcasterMp3())) {
if (!is_null($episode->podcasterMp3())) {
$audioFile = $episode->audio($episode->podcasterMp3()->first())->first();

if (is_null($audioFile)) {
return null;
}

return $audioFile;
}

$audioFile = $episode->audio()->first();

if (is_null($audioFile)) {
if (is_null($audioFile)) {
return null;
}

Expand Down Expand Up @@ -217,10 +220,10 @@ public function getPodloveGroups($episodeSlug)

public function getPodloveContributors($contributorsField, $contributorRoles, $contributorGroups)
{
if($contributorRoles->toStructure()->isEmpty() || $contributorGroups->toStructure()->isEmpty()) {
if ($contributorRoles->toStructure()->isEmpty() || $contributorGroups->toStructure()->isEmpty()) {
return [];
}

$contributors = [];
$roles = $contributorRoles->toStructure();
$groups = $contributorGroups->toStructure();
Expand Down Expand Up @@ -451,4 +454,33 @@ public function getPodloveConfigJson($episode)

return $config;
}

public function getAppleMetadata($endpoint)
{
$keyValueList = [];

if (option('mauricerenck.podcaster.useApi', true)) {
$apiCache = kirby()->cache('mauricerenck.podcaster');
$jsonString = $apiCache->get($endpoint);

if ($jsonString === null) {
$response = new Remote('https://api.podcaster-plugin.com/' . $endpoint);
$apiCache->set($endpoint, $response->content(), 7 * 24 * 60);
}
} else {
$jsonString = file_get_contents(__DIR__ . '/../res/' . $endpoint . '.json');
}

$json = json_decode($jsonString, JSON_OBJECT_AS_ARRAY);

foreach ($json as $key => $label) {
$keyValueList[] = ['text' => $label, 'value' => $key];
}

if (is_null($keyValueList)) {
return [];
}

return $keyValueList;
}
}
10 changes: 10 additions & 0 deletions app/SiteMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace mauricerenck\Podcaster;

return [
'getAppleMetadata' => function ($endpoint = 'categories') {
$podcast = new Podcast();
return $podcast->getAppleMetadata($endpoint);
}
];
14 changes: 8 additions & 6 deletions blueprints/tabs/episode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ columns:
label: Language
type: select
options:
type: api
url: "{{ site.url('') }}/podcaster/api/languages"
type: query
query: site.getAppleMetadata('languages')
value: '{{ item.value }}'
text: '{{ item.text }}'
required: true
podcasterTranscriptFile:
type: files
Expand Down Expand Up @@ -177,16 +179,16 @@ columns:
type: select
label: Role
options:
type: api
url: "{{ site.url('') }}/podcaster/podlove/roles/{{ page.uri }}"
type: query
query: page.podloveRoles
text: '{{ item.title }}'
value: '{{ item.id }}'
contributorGroup:
type: select
label: Group
options:
type: api
url: "{{ site.url('') }}/podcaster/podlove/groups/{{ page.uri }}"
type: query
query: page.podloveGroups
text: '{{ item.title }}'
value: '{{ item.id }}'
columns:
Expand Down
173 changes: 88 additions & 85 deletions blueprints/tabs/feed-details.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,92 @@
label: Show details
icon: star
columns:
- width: 1/1
sections:
spacer:
type: fields
fields:
headlineInfos:
type: headline
label: Podcast details
- width: 1/4
sections:
graphics:
type: fields
fields:
podcasterCover:
type: files
label: Cover Image
layout: cards
multiple: false
template: podcaster-cover
query: page.images
image:
cover: true
ratio: 1/1
- width: 2/4
sections:
infos:
type: fields
fields:
podcasterTitle:
label: Podcast Title
type: text
required: true
podcasterSubtitle:
label: Podcast Subtitle
type: text
podcasterDescription:
label: Description
type: textarea
size: medium
podcasterCopyright:
label: Copyright
type: text
required: true

- width: 1/4
sections:
taxonomy:
type: fields
fields:
podcasterKeywords:
label: Apple Keywords
type: tags
podcasterCategories:
label: Apple Categories
type: structure
required: true
fields:
podcasterMainCategory:
label: Main
type: select
options:
type: api
url: "{{ site.url('') }}/podcaster/api/categories"
podcasterType:
label: Podcast type
type: radio
default: episodic
options:
episodic: Episodic
serial: Serial
podcasterLanguage:
label: Language
type: select
options:
type: api
url: "{{ site.url('') }}/podcaster/api/languages"
required: true
podcasterAuthor:
label: Author
type: users
max: 1
podcasterOwner:
label: Owner
type: users
max: 1
- width: 1/1
sections:
spacer:
type: fields
fields:
headlineInfos:
type: headline
label: Podcast details
- width: 1/4
sections:
graphics:
type: fields
fields:
podcasterCover:
type: files
label: Cover Image
layout: cards
multiple: false
template: podcaster-cover
query: page.images
image:
cover: true
ratio: 1/1
- width: 2/4
sections:
infos:
type: fields
fields:
podcasterTitle:
label: Podcast Title
type: text
required: true
podcasterSubtitle:
label: Podcast Subtitle
type: text
podcasterDescription:
label: Description
type: textarea
size: medium
podcasterCopyright:
label: Copyright
type: text
required: true

- width: 1/4
sections:
taxonomy:
type: fields
fields:
podcasterKeywords:
label: Apple Keywords
type: tags
podcasterCategories:
label: Apple Categories
type: structure
required: true
fields:
podcasterMainCategory:
label: Main
type: select
options:
type: query
query: site.getAppleMetadata('categories')
value: '{{ item.value }}'
text: '{{ item.text }}'
podcasterType:
label: Podcast type
type: radio
default: episodic
options:
episodic: Episodic
serial: Serial
podcasterLanguage:
label: Language
type: select
options:
type: query
query: site.getAppleMetadata('languages')
value: '{{ item.value }}'
text: '{{ item.text }}'
required: true
podcasterAuthor:
label: Author
type: users
max: 1
podcasterOwner:
label: Owner
type: users
max: 1
Loading

0 comments on commit 844c73b

Please sign in to comment.