Gallery: add prune button (behold 100), webhook automation, shell_command
This commit is contained in:
@@ -5,5 +5,5 @@ panel: true
|
|||||||
|
|
||||||
cards:
|
cards:
|
||||||
- type: iframe
|
- type: iframe
|
||||||
url: /local/snapshots/indkorsel_loader.html?v=20260516130000
|
url: /local/snapshots/indkorsel_loader.html?v=20260516103510
|
||||||
aspect_ratio: 100%
|
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'
|
- alias: 'Snapshot ved person i indkorsel'
|
||||||
description: >
|
description: >
|
||||||
Gemmer et tidsstemplet snapshot + opdaterer latest.jpg + regenererer HTML-galleri,
|
Gemmer et tidsstemplet snapshot + opdaterer latest.jpg + regenererer HTML-galleri,
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
indkorsel_generate_gallery: "/usr/local/bin/docker exec homeassistant python3 /config/python_scripts/generate_indkorsel_gallery.py"
|
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"
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ html = f"""<!DOCTYPE html>
|
|||||||
<meta http-equiv="Pragma" content="no-cache">
|
<meta http-equiv="Pragma" content="no-cache">
|
||||||
<meta http-equiv="Expires" content="0">
|
<meta http-equiv="Expires" content="0">
|
||||||
<style>
|
<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}}
|
*{{box-sizing:border-box;margin:0;padding:0}}
|
||||||
body{{background:#111;color:#ddd;font-family:sans-serif;padding:10px}}
|
body{{background:#111;color:#ddd;font-family:sans-serif;padding:10px}}
|
||||||
h2{{padding:8px 0 14px;font-size:13px;opacity:.5;font-weight:normal}}
|
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}}
|
.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>
|
</style>
|
||||||
</head><body>
|
</head><body>
|
||||||
<h2>Viser {len(files)} person-snapshots – Indkorsel</h2>
|
<h2>Viser {len(files)} person-snapshots – 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 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 – tryk for at opdatere</div>
|
<div id="reload-badge" class="reload-badge" onclick="window.location.reload(true)">Nye billeder – tryk for at opdatere</div>
|
||||||
<div class="modal" id="modal">
|
<div class="modal" id="modal">
|
||||||
@@ -124,6 +129,21 @@ html = f"""<!DOCTYPE html>
|
|||||||
document.getElementById('modal').addEventListener('click', function(e){{
|
document.getElementById('modal').addEventListener('click', function(e){{
|
||||||
if(e.target === this) closeModal();
|
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
|
// Tjek hvert 60 sek om der er en nyere version af galleriet
|
||||||
setInterval(() => {{
|
setInterval(() => {{
|
||||||
fetch('/local/snapshots/indkorsel_loader.html?_=' + Date.now())
|
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
@@ -3,5 +3,5 @@
|
|||||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||||||
<meta http-equiv="Pragma" content="no-cache">
|
<meta http-equiv="Pragma" content="no-cache">
|
||||||
<meta http-equiv="Expires" content="0">
|
<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>
|
</head><body></body></html>
|
||||||
Reference in New Issue
Block a user