updated expressjs project to add a 'copy link' button
This commit is contained in:
@@ -411,6 +411,7 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
|
||||
<div class="muted">Noch ${formatCountdown(item.expires_at)}</div>
|
||||
</td>
|
||||
<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`)}">
|
||||
<button type="submit" class="secondary">Löschen</button>
|
||||
</form>
|
||||
@@ -474,6 +475,7 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
|
||||
const uploadForm = document.getElementById('upload-form');
|
||||
const progress = document.getElementById('upload-progress');
|
||||
const status = document.getElementById('upload-status');
|
||||
const copyButtons = document.querySelectorAll('.copy-link');
|
||||
uploadForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
status.textContent = '';
|
||||
@@ -498,6 +500,25 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
|
||||
});
|
||||
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>
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user