public URLs are easy to copy
This commit is contained in:
parent
f4fbfa3155
commit
2cd6d94172
2 changed files with 33 additions and 1 deletions
|
@ -126,6 +126,7 @@ def list(request: Request):
|
|||
query = conn.query(database.Original).order_by(-database.Original.id).limit(100)
|
||||
for original in query:
|
||||
files.append(original.__dict__)
|
||||
files[-1]["url"] = CONFIG["public"]["baseurl"] + "/dl/" + original.filepath
|
||||
data = {"files": files}
|
||||
|
||||
if "application/json" in request.headers.get("accept", ""):
|
||||
|
|
|
@ -16,11 +16,42 @@
|
|||
<tbody>
|
||||
{% for orig in files %}
|
||||
<tr>
|
||||
<td class="name">{{orig.name}}</td>
|
||||
<td class="name">
|
||||
<span>{{orig.name}}</span>
|
||||
<button class="copy" data-text="{{orig.url}}">📋</button>
|
||||
</td>
|
||||
<td class="size">{{orig.size}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
function live (eventType, elementQuerySelector, cb) {
|
||||
document.addEventListener(eventType, function (event) {
|
||||
|
||||
var qs = document.querySelectorAll(elementQuerySelector);
|
||||
|
||||
if (qs) {
|
||||
var el = event.target, index = -1;
|
||||
while (el && ((index = Array.prototype.indexOf.call(qs, el)) === -1)) {
|
||||
el = el.parentElement;
|
||||
}
|
||||
|
||||
if (index > -1) {
|
||||
cb.call(el, event);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (navigator && navigator.clipboard && navigator.clipboard.writeText) { // supported
|
||||
live('click', 'button.copy',
|
||||
function copy(evt) {
|
||||
const url = evt.target.dataset.text;
|
||||
navigator.clipboard.writeText(url);
|
||||
});
|
||||
} else {
|
||||
document.querySelectorAll(".filelist tbody td.name button.copy").forEach(function(el) { el.remove() })
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue