| 1 | <%# Beheer → Media: image library + cleanup (the Audio half links out to /admin/audio). %>
|
|---|
| 2 | <div class="admin-wrap" style="max-width:980px;margin:0 auto;padding:1.5rem 1rem;">
|
|---|
| 3 | <a href="/admin" class="btn" style="margin-bottom:1rem;display:inline-block;">← <%= t('nav.admin') %></a>
|
|---|
| 4 | <h1 style="font-family:var(--display,serif);margin:.2rem 0 1rem;"><%= t('admin.t_media') %></h1>
|
|---|
| 5 |
|
|---|
| 6 | <%- include('../partials/media-tabs', { active: 'images', audioOn: audioOn }) %>
|
|---|
| 7 |
|
|---|
| 8 | <% if (success) { %><p style="background:rgba(60,160,90,.15);border:1px solid rgba(60,160,90,.4);padding:.5rem .8rem;border-radius:8px;"><%= success %></p><% } %>
|
|---|
| 9 |
|
|---|
| 10 | <div style="display:flex;justify-content:space-between;align-items:center;gap:1rem;flex-wrap:wrap;margin-bottom:1rem;">
|
|---|
| 11 | <p style="margin:0;opacity:.75;">
|
|---|
| 12 | <%= items.length %> <%= t('admin.media_count') %><% if (unusedCount) { %> · <strong><%= unusedCount %></strong> <%= t('admin.media_unused') %><% } %>
|
|---|
| 13 | </p>
|
|---|
| 14 | <% if (unusedCount) { %>
|
|---|
| 15 | <button type="button" id="media-cleanup" class="btn" style="background:#b4452e;color:#fff;border-color:#b4452e;">🗑 <%= t('admin.media_cleanup') %> (<%= unusedCount %>)</button>
|
|---|
| 16 | <% } %>
|
|---|
| 17 | </div>
|
|---|
| 18 |
|
|---|
| 19 | <% if (!items.length) { %>
|
|---|
| 20 | <p style="opacity:.7;"><%= t('admin.media_empty') %></p>
|
|---|
| 21 | <% } else { %>
|
|---|
| 22 | <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:1rem;">
|
|---|
| 23 | <% items.forEach(function(it){ %>
|
|---|
| 24 | <div class="media-card" data-file="<%= it.file %>" style="border:1px solid var(--rule,rgba(128,128,128,.25));border-radius:10px;overflow:hidden;background:var(--paper-2,rgba(128,128,128,.06));">
|
|---|
| 25 | <div style="position:relative;aspect-ratio:1;background:#0a0e1a;">
|
|---|
| 26 | <img src="<%= thumb(it.url, 320) %>" alt="" loading="lazy" decoding="async" style="width:100%;height:100%;object-fit:cover;display:block;">
|
|---|
| 27 | <% if (it.hasVideo) { %><span title="animated cover" style="position:absolute;top:6px;right:6px;background:rgba(0,0,0,.6);border-radius:6px;padding:0 6px;font-size:13px;">🎬</span><% } %>
|
|---|
| 28 | <% if (!it.usedCount) { %><span style="position:absolute;top:6px;left:6px;background:#b4452e;color:#fff;border-radius:6px;padding:1px 6px;font-size:11px;"><%= t('admin.media_unused') %></span><% } %>
|
|---|
| 29 | </div>
|
|---|
| 30 | <div style="padding:.5rem .6rem;font-size:13px;">
|
|---|
| 31 | <div style="opacity:.7;"><%= it.kb %> KB · <%= it.usedCount %>×</div>
|
|---|
| 32 | <div style="display:flex;gap:.4rem;margin-top:.45rem;">
|
|---|
| 33 | <button type="button" class="btn" style="padding:3px 8px;font-size:12px;" data-copy="<%= it.url %>"><%= t('admin.media_copy') %></button>
|
|---|
| 34 | <button type="button" class="btn" style="padding:3px 8px;font-size:12px;background:transparent;border-color:#b4452e;color:#b4452e;" data-del="<%= it.file %>">🗑</button>
|
|---|
| 35 | </div>
|
|---|
| 36 | </div>
|
|---|
| 37 | </div>
|
|---|
| 38 | <% }) %>
|
|---|
| 39 | </div>
|
|---|
| 40 | <% } %>
|
|---|
| 41 | </div>
|
|---|
| 42 |
|
|---|
| 43 | <script>
|
|---|
| 44 | (function () {
|
|---|
| 45 | if (window.__mediaWired) return; window.__mediaWired = true;
|
|---|
| 46 | var T = <%- JSON.stringify({ copy: t('admin.media_copy'), delC: t('admin.media_del_confirm'), cleanC: t('admin.media_cleanup_confirm') }) %>;
|
|---|
| 47 | document.addEventListener('click', function (e) {
|
|---|
| 48 | var c = e.target.closest('[data-copy]');
|
|---|
| 49 | if (c) {
|
|---|
| 50 | var u = location.origin + c.getAttribute('data-copy');
|
|---|
| 51 | var done = function () { var o = c.textContent; c.textContent = '✓'; setTimeout(function () { c.textContent = o === '✓' ? T.copy : o; }, 1200); };
|
|---|
| 52 | if (navigator.clipboard) navigator.clipboard.writeText(u).then(done).catch(function () { window.prompt('URL', u); });
|
|---|
| 53 | else window.prompt('URL', u);
|
|---|
| 54 | return;
|
|---|
| 55 | }
|
|---|
| 56 | var d = e.target.closest('[data-del]');
|
|---|
| 57 | if (d) {
|
|---|
| 58 | if (!window.confirm(T.delC)) return;
|
|---|
| 59 | fetch('/admin/media/delete', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ file: d.getAttribute('data-del') }) })
|
|---|
| 60 | .then(function (r) { return r.json(); })
|
|---|
| 61 | .then(function (j) { if (j && j.ok) { var card = d.closest('.media-card'); if (card) card.remove(); } else window.alert((j && j.error) || 'Error'); })
|
|---|
| 62 | .catch(function () { window.alert('Error'); });
|
|---|
| 63 | return;
|
|---|
| 64 | }
|
|---|
| 65 | if (e.target.closest('#media-cleanup')) {
|
|---|
| 66 | if (!window.confirm(T.cleanC)) return;
|
|---|
| 67 | fetch('/admin/media/cleanup', { method: 'POST', credentials: 'same-origin' })
|
|---|
| 68 | .then(function (r) { return r.json(); })
|
|---|
| 69 | .then(function (j) { location.href = '/admin/media?success=' + encodeURIComponent(((j && j.removed) || 0) + ' file(s) removed'); })
|
|---|
| 70 | .catch(function () { window.alert('Error'); });
|
|---|
| 71 | }
|
|---|
| 72 | });
|
|---|
| 73 | })();
|
|---|
| 74 | </script>
|
|---|