Phase 2.2

This commit is contained in:
Gogs
2026-07-07 13:54:34 +02:00
parent 32d81f601a
commit a3acacf177
4 changed files with 45 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
<?php
require_once '/var/www/src/bootstrap.php';
$versionFile = '/var/www/cache/guide.version';
ApiResponse::json([
'ok' => true,
'version' => file_exists($versionFile)
? trim(file_get_contents($versionFile))
: '0',
]);
+1
View File
@@ -48,6 +48,7 @@ document.addEventListener('DOMContentLoaded', () => {
const liveNow = new LiveEngine({
url: '/api/live-now.php',
versionUrl: '/api/version.php',
interval: 30000,
gridSelector: '[data-live-now-grid]',
itemKey: item => item.channel_id,
+27
View File
@@ -31,6 +31,8 @@ window.TVGuideLive = {
window.LiveEngine = class LiveEngine {
constructor(options) {
this.url = options.url;
this.versionUrl = options.versionUrl ?? null;
this.version = null;
this.interval = options.interval ?? 30000;
this.gridSelector = options.gridSelector;
this.itemKey = options.itemKey;
@@ -49,10 +51,35 @@ window.LiveEngine = class LiveEngine {
return document.querySelector(this.gridSelector);
}
async hasChanged() {
if (!this.versionUrl) {
return true;
}
const data = await TVGuideLive.fetchJson(this.versionUrl);
const version = String(data.version ?? '0');
if (this.version === null) {
this.version = version;
return true;
}
if (this.version !== version) {
this.version = version;
return true;
}
return false;
}
async refresh() {
const grid = this.getGrid();
if (!grid) return;
if (!(await this.hasChanged())) {
return;
}
try {
const data = await TVGuideLive.fetchJson(this.url);
const items = data.items ?? [];
+5
View File
@@ -112,6 +112,11 @@ class XmlTvCacheService
$this->cacheFile,
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
);
file_put_contents(
dirname($this->cacheFile) . '/guide.version',
(string)filemtime($this->cacheFile)
);
}
private function parseTime(string $value): ?DateTime