caching podcasts

This commit is contained in:
root 2022-11-30 17:49:05 +01:00
parent 08dc666b24
commit 1804879022
2 changed files with 24 additions and 8 deletions

View file

@ -6,7 +6,7 @@ podcast_ror.all:
requirements:
_access: 'TRUE'
options:
no_cache: 'TRUE'
no_cache: 'FALSE'
podcast_ror.bytype:
path: '/podcast/by-type/{contentType}/podcast.xml'
defaults:
@ -15,7 +15,7 @@ podcast_ror.bytype:
requirements:
_access: 'TRUE'
options:
no_cache: 'TRUE'
no_cache: 'FALSE'
podcast_ror.bytrxid:
path: '/podcast/by-trx-id/{trxID}/podcast.xml'
defaults:
@ -24,4 +24,4 @@ podcast_ror.bytrxid:
requirements:
_access: 'TRUE'
options:
no_cache: 'TRUE'
no_cache: 'FALSE'

View file

@ -94,18 +94,34 @@ class PodcastRorController extends ControllerBase {
public function podcast($query, $description) {
// TODO: add $title argument to the function
$template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
$tmpl_data = [ 'ror' => array('podcast' => $this->query($query),
$query_results = $this->query($query);
$tmpl_data = [ 'ror' => array('podcast' => $query_results,
'url' => \Drupal::service('path.current')->getPath(),
'description' => $description,
'title' => 'Radio Onda Rossa',
)];
//$variables['ror']['url'] =
$xml = $template->render($tmpl_data);
$resp = new Response($xml, 200, array(
$headers = array(
'Content-Type' => 'application/rss+xml',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET',
));
);
$nodes = $tmpl_data['ror']['podcast']['nodes'];
$lastmodtime = 0;
if( !empty($nodes) ) {
foreach($nodes as $nid => $node) {
$modtime = intval($node['changed'][0]['value']);
if($modtime > $lastmodtime) {
$lastmodtime = $modtime;
}
}
}
$xml = $template->render($tmpl_data);
$resp = new Response($xml, 200, $headers);
$resp->setPublic();
$resp->setTtl(300);
if($lastmodtime !== 0) {
$resp->setLastModified(\DateTime::createFromFormat('U',$lastmodtime));
}
return $resp;
}
public function podcastAll() {