mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
Admin: add HA entities, News CRUD, Proxmox VMs tabs; news.php merges custom pinned entries
This commit is contained in:
+24
-7
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// News endpoint — serves from api_cache (refreshed every 30 min by cron)
|
||||
// News endpoint — serves from api_cache + custom pinned news from admin kb_facts
|
||||
|
||||
$cached = JarvisDB::query(
|
||||
'SELECT data, UNIX_TIMESTAMP(updated_at) as ts FROM api_cache WHERE cache_key=? LIMIT 1',
|
||||
@@ -9,12 +9,29 @@ $cached = JarvisDB::query(
|
||||
if ($cached && !empty($cached[0]['data'])) {
|
||||
$out = json_decode($cached[0]['data'], true);
|
||||
$out['cache_age_s'] = (int)(time() - (int)$cached[0]['ts']);
|
||||
echo json_encode($out);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'categories' => [],
|
||||
'total' => 0,
|
||||
$out = [
|
||||
'categories' => [],
|
||||
'total' => 0,
|
||||
'cache_age_s' => -1,
|
||||
'message' => 'News feed warming up — available within 5 minutes.',
|
||||
]);
|
||||
'message' => 'News feed warming up — available within 5 minutes.',
|
||||
];
|
||||
}
|
||||
|
||||
// Prepend custom/pinned news items added via admin portal
|
||||
$custom = JarvisDB::query(
|
||||
"SELECT fact_key as title, fact_value as url, updated_at FROM kb_facts WHERE category='custom_news' ORDER BY id DESC"
|
||||
);
|
||||
if (!empty($custom)) {
|
||||
$pinned = array_map(fn($r) => [
|
||||
'title' => $r['title'],
|
||||
'url' => $r['url'] ?: null,
|
||||
'source' => 'JARVIS',
|
||||
'published' => $r['updated_at'],
|
||||
'pinned' => true,
|
||||
], $custom);
|
||||
// Insert pinned as first category
|
||||
$out['categories'] = array_merge(['pinned' => $pinned], $out['categories'] ?? []);
|
||||
}
|
||||
|
||||
echo json_encode($out);
|
||||
|
||||
Reference in New Issue
Block a user