Files
Glimmer/internal/server/templates/admin_bin.html
lucioandClaude Opus 4.8 87477556e2 Redesign admin Pastes page as Xiaohongshu-style cards with previews
- Replace the pastes table with a masonry card grid: each card shows the
  paste's first image as a thumbnail, a short plain-text summary, meta badges,
  and Copy link / Edit / QR / Delete actions.
- Clicking anywhere on a card (except the action buttons) opens an in-page
  preview modal with the rendered paste in an iframe; it can be expanded to the
  main content area or closed (Esc/backdrop/button). Keyboard accessible.
- Generate and cache 512px (long side) JPEG thumbnails for uploaded images on
  first request (GET /uploads/thumb/{filename}); also generated at upload time
  and invalidated on resize/delete. WebP falls back to the original.
- Sync the public paste pages (bin_view, bin_token) to the dark theme so they
  match the rest of the app and the preview iframe.
- Relax framing headers to same-origin (X-Frame-Options SAMEORIGIN,
  frame-ancestors 'self') so the same-origin preview iframe can load; cross-site
  framing stays blocked.
- Document the new thumbnail route in the README routes table.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-05 00:23:51 -07:00

185 lines
6.9 KiB
HTML

<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pastes — Admin</title>
<link rel="stylesheet" href="/static/pico.min.css">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav>
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
<ul>
<li><a href="/">Home</a></li>
<li>
<form method="post" action="/admin/logout" style="margin:0">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary btn-sm">Logout</button>
</form>
</li>
</ul>
</nav>
<div class="admin-tabs">
<a href="/admin" class="tab-link">Links</a>
<a href="/admin/bin" class="tab-link active">Pastes</a>
<a href="/admin/uploads" class="tab-link">Uploads</a>
</div>
<main class="container" style="max-width:1180px">
{{if .Error}}
<article aria-label="error" class="alert-error">{{.Error}}</article>
{{end}}
<div class="section-header" style="padding-left:0;padding-right:0">
<hgroup>
<h2>Pastes</h2>
<p>{{len .Pastes}} pastes</p>
</hgroup>
<a href="/admin/bin/new" role="button" class="btn-sm">+ New Paste</a>
</div>
{{if .Pastes}}
<div class="pcard-grid">
{{range .Pastes}}
<article class="pcard js-preview" data-name="{{.Name}}" data-token="{{.Token}}" data-title="{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}" role="button" tabindex="0">
{{if .ThumbURL}}
<div class="pcard-imgwrap">
<img class="pcard-img" src="{{.ThumbURL}}" alt="" loading="lazy">
</div>
{{end}}
<div class="pcard-body">
<h3 class="pcard-title">{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}</h3>
{{if .Summary}}<p class="pcard-summary">{{.Summary}}</p>{{end}}
<div class="pcard-meta">
<mark class="badge-format">{{.Format}}</mark>
{{if .Token}}<mark class="badge-token">&#128274;</mark>{{else}}<mark class="badge-public">public</mark>{{end}}
{{if .Hidden}}<mark class="badge-hidden">hidden</mark>{{end}}
<span class="pcard-date">{{.UpdatedAt.Format "01-02 15:04"}}</span>
</div>
<div class="pcard-actions" role="group">
<button type="button" class="outline" onclick="copyPasteLink('{{.Name}}','{{.Token}}', this)">Copy link</button>
<a href="/admin/bin/edit/{{.ID}}" role="button" class="outline">Edit</a>
<button type="button" class="outline" onclick="showBinQR('{{.Name}}', false)">QR</button>
<form method="post" action="/admin/bin/delete/{{.ID}}" onsubmit="return confirm('Delete paste {{.Name}}?')">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="outline secondary">Del</button>
</form>
</div>
</div>
</article>
{{end}}
</div>
{{else}}
<div class="empty-state">
<span class="empty-icon">&#128196;</span>
<p>No pastes yet.</p>
<a href="/admin/bin/new">Create your first paste</a>
</div>
{{end}}
</main>
<dialog id="preview-dialog" class="preview-dialog">
<div class="preview-head">
<span class="preview-title" id="preview-title">Preview</span>
<div class="preview-actions">
<a id="preview-open" href="#" target="_blank" rel="noopener" role="button" class="outline btn-sm">Open &#8599;</a>
<button type="button" class="outline btn-sm" id="preview-expand" onclick="toggleExpand()" aria-label="Expand">&#8690;</button>
<button type="button" class="btn-sm preview-close" onclick="closePreview()" aria-label="Close">&#10005;</button>
</div>
</div>
<iframe id="preview-frame" class="preview-frame" src="about:blank" title="Paste preview"></iframe>
</dialog>
<dialog id="qr-dialog">
<article>
<header>
<button aria-label="Close" rel="prev" onclick="document.getElementById('qr-dialog').close()"></button>
<h3 id="qr-title">QR Code</h3>
</header>
<div id="qr-container" style="text-align:center"></div>
</article>
</dialog>
<script>
function previewURL(name, token) {
var u = '/bin/' + encodeURIComponent(name);
if (token) u += '/' + encodeURIComponent(token);
return u;
}
function openPreview(name, token, title) {
var dlg = document.getElementById('preview-dialog');
var url = previewURL(name, token);
document.getElementById('preview-frame').src = url;
document.getElementById('preview-open').href = url;
document.getElementById('preview-title').textContent = title || name;
dlg.classList.remove('expanded');
document.getElementById('preview-expand').innerHTML = '&#8690;';
document.getElementById('preview-expand').setAttribute('aria-label', 'Expand');
dlg.showModal();
}
function closePreview() {
document.getElementById('preview-dialog').close();
}
function toggleExpand() {
var dlg = document.getElementById('preview-dialog');
var expanded = dlg.classList.toggle('expanded');
var btn = document.getElementById('preview-expand');
btn.innerHTML = expanded ? '&#8689;' : '&#8690;';
btn.setAttribute('aria-label', expanded ? 'Shrink' : 'Expand');
}
function copyPasteLink(name, token, btn) {
var url = location.origin + previewURL(name, token);
navigator.clipboard.writeText(url).then(function() {
var orig = btn.textContent;
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = orig; }, 1500);
});
}
// Clicking anywhere on a card opens the preview, except on the action
// buttons. Data attributes avoid quoting issues with paste titles.
document.querySelectorAll('.js-preview').forEach(function(el) {
el.addEventListener('click', function(e) {
if (e.target.closest('.pcard-actions')) return;
openPreview(el.dataset.name, el.dataset.token, el.dataset.title);
});
el.addEventListener('keydown', function(e) {
if ((e.key === 'Enter' || e.key === ' ') && !e.target.closest('.pcard-actions')) {
e.preventDefault();
openPreview(el.dataset.name, el.dataset.token, el.dataset.title);
}
});
});
// Clear the iframe when the dialog is dismissed via Esc / backdrop / button.
document.getElementById('preview-dialog').addEventListener('close', function() {
document.getElementById('preview-frame').src = 'about:blank';
});
function showBinQR(name, full) {
var container = document.getElementById('qr-container');
var title = document.getElementById('qr-title');
container.innerHTML = '<p>Loading...</p>';
title.textContent = full ? 'Full QR Code (with token)' : 'QR Code';
document.getElementById('qr-dialog').showModal();
var url = '/admin/bin/qr/' + encodeURIComponent(name);
if (full) url += '?full=1';
fetch(url)
.then(function(r) { return r.text(); })
.then(function(svg) {
var fullLink = location.origin + '/bin/' + name;
var note = '';
if (full) {
note = '<small style="color:var(--pico-muted-color)">(includes access token)</small>';
}
container.innerHTML = svg +
'<p style="margin-top:0.5rem;word-break:break-all">' + fullLink + '</p>' + note;
});
}
</script>
</body>
</html>