Move every inline <script> block and on*= attribute out of the templates into per-page files under static/js/, then tighten the CSP to script-src 'self' so injected inline scripts are actually blocked. - static/js/base.js: QR modal, form[data-confirm] submit confirmation, and a shared glimmerCopy clipboard helper (loaded by base.html) - One script per template: index, bin_view, bin_token, admin, admin_edit, admin_bin, admin_bin_edit, admin_uploads - Template data now flows through data-* attributes (data-slug, data-filename, data-max-mb, ...) instead of being interpolated into JS; confirm() prompts use data-confirm - style-src keeps unsafe-inline for the style="" attributes - Update CLAUDE.md / AGENTS.md with the no-inline-JS rule Verified in a live browser session: shorten flow, login, QR modal, paste editor (token radios, name preview), paste cards (preview dialog, expand/close), public paste view, token prompt redirect, and uploads page - no console errors or CSP violations. Co-Authored-By: Claude Fable 5 <[email protected]>
85 lines
3.7 KiB
HTML
85 lines
3.7 KiB
HTML
{{define "title"}}Pastes — Admin{{end}}
|
|
{{define "content"}}
|
|
|
|
<div class="page-header">
|
|
<div class="page-title">
|
|
<h1>Pastes</h1>
|
|
<p>{{len .Pastes}} paste{{if ne (len .Pastes) 1}}s{{end}} — Markdown & plain text, optionally token-protected.</p>
|
|
</div>
|
|
<div class="page-actions">
|
|
<a href="/admin/bin/new" class="btn btn-primary">
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:18px;height:18px"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>
|
|
New Paste
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{{if .Error}}
|
|
<div class="alert alert-error">{{.Error}}</div>
|
|
{{end}}
|
|
|
|
{{if .Pastes}}
|
|
<div class="paste-grid">
|
|
{{range .Pastes}}
|
|
<article class="paste-card js-preview" data-name="{{.Name}}" data-token="{{.Token}}" data-title="{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}">
|
|
{{if .ThumbURL}}
|
|
<div class="paste-card-thumb">
|
|
<img src="{{.ThumbURL}}" alt="" loading="lazy">
|
|
</div>
|
|
{{else}}
|
|
<div class="paste-card-thumb">
|
|
<span class="paste-card-thumb-empty">{{.Format}}</span>
|
|
</div>
|
|
{{end}}
|
|
<div class="paste-card-body">
|
|
<h3 class="paste-card-title">{{if .Title}}{{.Title}}{{else}}{{.Name}}{{end}}</h3>
|
|
{{if .Summary}}<p class="paste-card-summary">{{.Summary}}</p>{{end}}
|
|
<div class="paste-card-meta">
|
|
<span class="tag-pill badge-format">{{.Format}}</span>
|
|
{{if .Token}}
|
|
<span class="tag-pill badge-token">🔒</span>
|
|
{{else}}
|
|
<span class="tag-pill badge-public">public</span>
|
|
{{end}}
|
|
{{if .Hidden}}<span class="tag-pill badge-hidden">hidden</span>{{end}}
|
|
<span class="paste-card-date">{{.UpdatedAt.Format "01-02 15:04"}}</span>
|
|
</div>
|
|
</div>
|
|
<div class="paste-card-actions">
|
|
<button type="button" class="btn btn-secondary btn-sm js-copy-link">Copy link</button>
|
|
<a href="/admin/bin/edit/{{.ID}}" class="btn btn-secondary btn-sm">Edit</a>
|
|
<button type="button" class="btn btn-secondary btn-sm js-bin-qr">QR</button>
|
|
<form method="post" action="/admin/bin/delete/{{.ID}}" style="display:inline" data-confirm="Delete paste {{.Name}}?">
|
|
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
|
<button type="submit" class="btn btn-danger btn-sm">Del</button>
|
|
</form>
|
|
</div>
|
|
</article>
|
|
{{end}}
|
|
</div>
|
|
{{else}}
|
|
<div class="card">
|
|
<div class="empty-state">
|
|
<span class="empty-state-icon">📄</span>
|
|
<p class="empty-state-text">No pastes yet.</p>
|
|
<a href="/admin/bin/new" class="btn btn-primary empty-state-action">Create your first paste</a>
|
|
</div>
|
|
</div>
|
|
{{end}}
|
|
|
|
<!-- Paste preview dialog -->
|
|
<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" class="btn btn-secondary btn-sm">Open ↗</a>
|
|
<button type="button" class="btn btn-secondary btn-sm" id="preview-expand" aria-label="Expand">⤢</button>
|
|
<button type="button" class="btn btn-secondary btn-sm" id="preview-close" aria-label="Close">✕</button>
|
|
</div>
|
|
</div>
|
|
<iframe id="preview-frame" class="preview-frame" src="about:blank" title="Paste preview"></iframe>
|
|
</dialog>
|
|
|
|
<script src="/static/js/admin_bin.js"></script>
|
|
{{end}}
|