updated expressjs project to add a 'copy link' button

This commit is contained in:
Ludwig Lehnert
2026-01-12 17:24:28 +01:00
parent dbca041859
commit a79da3ffce

View File

@@ -411,6 +411,7 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
<div class="muted">Noch ${formatCountdown(item.expires_at)}</div> <div class="muted">Noch ${formatCountdown(item.expires_at)}</div>
</td> </td>
<td class="actions"> <td class="actions">
<button type="button" class="secondary copy-link" data-path="${fileUrl}">Link kopieren</button>
<form method="post" action="${baseUrl(`/files/${item.id}/delete`)}"> <form method="post" action="${baseUrl(`/files/${item.id}/delete`)}">
<button type="submit" class="secondary">Löschen</button> <button type="submit" class="secondary">Löschen</button>
</form> </form>
@@ -474,6 +475,7 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
const uploadForm = document.getElementById('upload-form'); const uploadForm = document.getElementById('upload-form');
const progress = document.getElementById('upload-progress'); const progress = document.getElementById('upload-progress');
const status = document.getElementById('upload-status'); const status = document.getElementById('upload-status');
const copyButtons = document.querySelectorAll('.copy-link');
uploadForm.addEventListener('submit', (event) => { uploadForm.addEventListener('submit', (event) => {
event.preventDefault(); event.preventDefault();
status.textContent = ''; status.textContent = '';
@@ -498,6 +500,25 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
}); });
xhr.send(new FormData(uploadForm)); xhr.send(new FormData(uploadForm));
}); });
copyButtons.forEach((button) => {
button.addEventListener('click', async () => {
const path = button.dataset.path || '';
const url = window.location.origin + path;
try {
await navigator.clipboard.writeText(url);
status.textContent = 'Link kopiert.';
} catch (err) {
const helper = document.createElement('textarea');
helper.value = url;
document.body.appendChild(helper);
helper.select();
document.execCommand('copy');
document.body.removeChild(helper);
status.textContent = 'Link kopiert.';
}
});
});
</script> </script>
`; `;