@@ -347,6 +404,57 @@
}
});
+ // Share functions
+ function openShareModal() {
+ document.getElementById('share-modal').classList.remove('hidden');
+ document.getElementById('share-result').classList.add('hidden');
+ loadShares();
+ }
+ function closeShareModal() {
+ document.getElementById('share-modal').classList.add('hidden');
+ }
+ async function createShare() {
+ const days = parseInt(document.getElementById('share-days').value);
+ const res = await fetch('/api/share/{{.Document.ID}}', {
+ method: 'POST',
+ headers: {'Content-Type': 'application/json'},
+ body: JSON.stringify({days: days})
+ });
+ if (res.ok) {
+ const data = await res.json();
+ const fullUrl = window.location.origin + data.url;
+ document.getElementById('share-url').value = fullUrl;
+ document.getElementById('share-result').classList.remove('hidden');
+ loadShares();
+ }
+ }
+ function copyShareUrl() {
+ const input = document.getElementById('share-url');
+ navigator.clipboard.writeText(input.value);
+ }
+ async function loadShares() {
+ const res = await fetch('/api/shares/{{.Document.ID}}');
+ const shares = await res.json();
+ const list = document.getElementById('shares-list');
+ if (!shares || shares.length === 0) {
+ list.innerHTML = '
No active shares
';
+ return;
+ }
+ list.innerHTML = shares.map(s => `
+
+
+ ${window.location.origin}/s/${s.Token}
+ ${s.ExpiresAt ? 'expires ' + s.ExpiresAt : 'permanent'}
+
+
+
+ `).join('');
+ }
+ async function revokeShare(token) {
+ await fetch('/api/share/' + token, {method: 'DELETE'});
+ loadShares();
+ }
+
async function deleteDocument() {
if (!confirm('Are you sure you want to delete this document?')) return;