Gallery: add prune button (behold 100), webhook automation, shell_command

This commit is contained in:
2026-05-16 10:35:28 +02:00
parent c394d6b974
commit 63288dbb4b
8 changed files with 256 additions and 198 deletions
@@ -5,5 +5,5 @@ panel: true
cards:
- type: iframe
url: /local/snapshots/indkorsel_loader.html?v=20260516130000
url: /local/snapshots/indkorsel_loader.html?v=20260516103510
aspect_ratio: 100%
@@ -1,3 +1,16 @@
- alias: 'Indkorsel: Slet gamle snapshots (behold 100)'
description: Køres via webhook fra galleriet sletter alle undtagen de 100 nyeste snapshots og regenererer galleriet.
trigger:
- platform: webhook
webhook_id: indkorsel_prune_100
allowed_methods: [POST]
local_only: true
action:
- action: shell_command.indkorsel_prune_keep_100
- delay: '00:00:02'
- action: shell_command.indkorsel_generate_gallery
mode: single
- alias: 'Snapshot ved person i indkorsel'
description: >
Gemmer et tidsstemplet snapshot + opdaterer latest.jpg + regenererer HTML-galleri,
+1
View File
@@ -1 +1,2 @@
indkorsel_generate_gallery: "/usr/local/bin/docker exec homeassistant python3 /config/python_scripts/generate_indkorsel_gallery.py"
indkorsel_prune_keep_100: "ls -1 /config/www/snapshots/indkorsel/*.jpg | grep -v '/latest.jpg$' | sort -r | tail -n +101 | xargs rm -f"
+21 -1
View File
@@ -56,6 +56,9 @@ html = f"""<!DOCTYPE html>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<style>
.prune-btn{{display:inline-block;margin-left:12px;padding:3px 10px;font-size:11px;border:1px solid #c44;background:transparent;color:#c88;border-radius:12px;cursor:pointer;vertical-align:middle;transition:background .15s,color .15s}}
.prune-btn:hover{{background:#c44;color:#fff}}
.prune-btn:disabled{{opacity:.4;cursor:default}}
*{{box-sizing:border-box;margin:0;padding:0}}
body{{background:#111;color:#ddd;font-family:sans-serif;padding:10px}}
h2{{padding:8px 0 14px;font-size:13px;opacity:.5;font-weight:normal}}
@@ -79,7 +82,9 @@ html = f"""<!DOCTYPE html>
.reload-badge{{position:fixed;bottom:14px;right:14px;background:#1a73e8;color:#fff;padding:6px 14px;border-radius:20px;font-size:12px;cursor:pointer;display:none;z-index:9998}}
</style>
</head><body>
<h2>Viser {len(files)} person-snapshots &ndash; Indkorsel</h2>
<h2>Viser {len(files)} person-snapshots &ndash; Indkorsel
<button class="prune-btn" id="pruneBtn" onclick="pruneSnapshots()" title="Slet alle undtagen de 100 nyeste">Behold sidste 100</button>
</h2>
{"<div class='grid'>" + items_html + "</div>" if files else "<div class='empty'>Ingen snapshots endnu.</div>"}
<div id="reload-badge" class="reload-badge" onclick="window.location.reload(true)">Nye billeder &#8211; tryk for at opdatere</div>
<div class="modal" id="modal">
@@ -124,6 +129,21 @@ html = f"""<!DOCTYPE html>
document.getElementById('modal').addEventListener('click', function(e){{
if(e.target === this) closeModal();
}});
function pruneSnapshots(){{
if(!confirm('Slet alle undtagen de 100 nyeste billeder?')) return;
const btn = document.getElementById('pruneBtn');
btn.disabled = true;
btn.textContent = 'Sletter...';
fetch('/api/webhook/indkorsel_prune_100', {{method:'POST'}})
.then(() => {{
btn.textContent = 'Færdig genindlæser...';
setTimeout(() => window.location.reload(true), 3500);
}})
.catch(() => {{
btn.disabled = false;
btn.textContent = 'Fejl prøv igen';
}});
}}
// Tjek hvert 60 sek om der er en nyere version af galleriet
setInterval(() => {{
fetch('/local/snapshots/indkorsel_loader.html?_=' + Date.now())
Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 34 KiB

File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -3,5 +3,5 @@
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="refresh" content="0; url=/local/snapshots/indkorsel_gallery.html?v=20260516130000">
<meta http-equiv="refresh" content="0; url=/local/snapshots/indkorsel_gallery.html?v=20260516103510">
</head><body></body></html>