Files
Glimmer/internal/server/templates/admin_uploads.html
T
lucioandClaude Fable 5 a9da249760 Remove unsafe-inline from script-src CSP
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]>
2026-06-09 20:14:30 -07:00

116 lines
6.4 KiB
HTML

{{define "title"}}Uploads — Admin{{end}}
{{define "content"}}
<div class="page-header">
<div class="page-title">
<h1>Uploads</h1>
<p>Manage your uploaded images and files. Use them in pastes via the markdown link.</p>
</div>
<div class="page-actions">
<a href="/admin/bin" class="btn btn-secondary">Back to pastes</a>
</div>
</div>
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
<div class="card card-flush">
<div class="card-header">
<div>
<h2 class="card-title">All uploads</h2>
<p class="card-subtitle">{{len .Uploads}} file{{if ne (len .Uploads) 1}}s{{end}} stored locally.</p>
</div>
<div class="upload-controls">
<button type="button" id="upload-img-btn" class="btn btn-primary btn-sm" data-max-mb="{{.UploadMaxMB}}" title="PNG, JPEG, GIF, WebP — up to 50 MB">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"/></svg>
Upload Image <small style="opacity:.6">(50 MB)</small>
</button>
<button type="button" id="upload-file-btn" class="btn btn-secondary btn-sm" title="Any file type — up to 5 MB">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"/></svg>
Upload File <small style="opacity:.6">(5 MB)</small>
</button>
<input type="file" id="img-input" accept="image/png,image/jpeg,image/gif,image/webp" style="display:none">
<input type="file" id="file-input" style="display:none">
<small id="upload-status" class="upload-status"></small>
</div>
</div>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th style="width: 90px;">Preview</th>
<th>File</th>
<th>Size</th>
<th>Dimensions</th>
<th>Uploaded</th>
<th class="col-actions">Actions</th>
</tr>
</thead>
<tbody>
{{range .Uploads}}
<tr>
<td>
{{if .IsImage}}
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">
<img src="{{.URL}}" style="max-width:72px; max-height:52px; object-fit:contain; border-radius:4px; border:1px solid var(--color-border)" alt="">
</a>
{{else}}
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer" style="font-size:1.5rem; text-decoration:none" title="Download file">📄</a>
{{end}}
</td>
<td>
<div style="display:flex; align-items:center; gap:0.5rem; flex-wrap:wrap;">
<span class="ext-chip">{{.Ext}}</span>
{{if .OriginalName}}<span style="font-size:0.9rem">{{.OriginalName}}</span>{{end}}
</div>
<code style="font-size:0.7rem; opacity:.6; display:block; margin-top:0.2rem;">{{.Filename}}</code>
</td>
<td id="size-{{.Filename}}">{{.SizeHuman}}</td>
<td id="dim-{{.Filename}}">{{if .Width}}{{.Width}}&times;{{.Height}}{{else}}—{{end}}</td>
<td>{{.ModTime.Format "2006-01-02 15:04"}}</td>
<td class="col-actions">
<div class="flex gap-1">
<button type="button" class="btn btn-secondary btn-sm js-copy-md" data-filename="{{.Filename}}" data-image="{{if .IsImage}}1{{end}}" data-original="{{.OriginalName}}">Copy</button>
{{if .CanResize}}<button type="button" class="btn btn-secondary btn-sm js-resize" data-filename="{{.Filename}}" data-width="{{.Width}}" data-height="{{.Height}}">Resize</button>{{end}}
<form method="post" action="/admin/uploads/delete/{{.Filename}}" style="display:inline" data-confirm="Delete this file?">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger btn-sm">Del</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr><td colspan="6">
<div class="empty-state">
<span class="empty-state-icon">📄</span>
<p class="empty-state-text">No uploads yet. Use the buttons above to upload an image or file.</p>
</div>
</td></tr>
{{end}}
</tbody>
</table>
</div>
</div>
<dialog id="resize-dialog">
<article>
<header>
<button class="js-resize-cancel" aria-label="Close"></button>
<h3>Resize Image</h3>
</header>
<p id="resize-current" class="text-muted" style="margin-bottom: 1rem;"></p>
<label class="form-label" for="resize-dim">Max dimension (px)</label>
<input type="number" id="resize-dim" value="1200" min="64" max="8192" step="1">
<small id="resize-status" class="text-muted" style="display:block; margin-top:0.5rem;"></small>
<footer>
<button type="button" class="btn btn-secondary js-resize-cancel">Cancel</button>
<button type="button" id="resize-confirm" class="btn btn-primary">Resize</button>
</footer>
</article>
</dialog>
<script src="/static/upload.js"></script>
<script src="/static/js/admin_uploads.js"></script>
{{end}}