Implement hidden paste feature with QR code generation and access token handling
This commit is contained in:
1 parent
22fe12012b
commit
f80903c7eb
10 files changed
+232
-33
No files matched your search
@@ -56,11 +56,13 @@
|
||||
<td><a href="/bin/{{.Name}}{{if .Token}}/{{.Token}}{{end}}" target="_blank">{{.Name}}</a></td>
|
||||
<td>{{.Title}}</td>
|
||||
<td><mark class="badge-format">{{.Format}}</mark></td>
|
||||
<td>{{if .Token}}<mark class="badge-token">🔒 token</mark>{{else}}<mark class="badge-public">public</mark>{{end}}</td>
|
||||
<td>{{if .Token}}<mark class="badge-token">🔒 token</mark>{{else}}<mark class="badge-public">public</mark>{{end}}{{if .Hidden}} <mark class="badge-hidden">hidden</mark>{{end}}</td>
|
||||
<td>{{.UpdatedAt.Format "2006-01-02 15:04"}}</td>
|
||||
<td>
|
||||
<div role="group">
|
||||
<a href="/admin/bin/edit/{{.ID}}" role="button" class="outline">Edit</a>
|
||||
<button type="button" class="outline" onclick="showBinQR('{{.Name}}', false)">QR</button>
|
||||
{{if .Token}}<button type="button" class="outline" onclick="showBinQR('{{.Name}}', true)">Full QR</button>{{end}}
|
||||
<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>
|
||||
@@ -84,5 +86,36 @@
|
||||
</figure>
|
||||
</article>
|
||||
</main>
|
||||
<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 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>
|
||||
Reference in new issue
Block a user