diff --git a/frontend/src/tools/dateien.jsx b/frontend/src/tools/dateien.jsx index 8e7d8e8..e39ab3c 100644 --- a/frontend/src/tools/dateien.jsx +++ b/frontend/src/tools/dateien.jsx @@ -220,11 +220,33 @@ function UploadShareManager({ toast }) { setShortening(null); }; - const copyLink = (token) => { + const copyLink = async (shareId, token) => { + // Wenn Kurz-URL vorhanden, die nehmen - sonst generieren + if (shortUrls[shareId]) { + navigator.clipboard?.writeText(shortUrls[shareId]).catch(()=>{}); + setCopied(token); setTimeout(()=>setCopied(null),2500); + return; + } + // Kurz-URL erst generieren + setShortening(shareId); const url = `${window.location.origin}/u/${token}`; - navigator.clipboard?.writeText(url).then(()=>{ setCopied(token); setTimeout(()=>setCopied(null),2000); }).catch(()=>{ - toast(url); - }); + try { + const r = await fetch(`https://is.gd/create.php?format=simple&url=${encodeURIComponent(url)}`); + const short = await r.text(); + if (short.startsWith('http')) { + setShortUrls(p=>({...p,[shareId]:short.trim()})); + navigator.clipboard?.writeText(short.trim()).catch(()=>{}); + setCopied(token); setTimeout(()=>setCopied(null),2500); + } else { + // Fallback auf Original-URL + navigator.clipboard?.writeText(url).catch(()=>{}); + setCopied(token); setTimeout(()=>setCopied(null),2500); + } + } catch { + navigator.clipboard?.writeText(url).catch(()=>{}); + setCopied(token); setTimeout(()=>setCopied(null),2500); + } + setShortening(null); }; const loadLogs = () => { @@ -336,22 +358,15 @@ function UploadShareManager({ toast }) {
{!!s.is_active && !expired && ( <> - {sharePws[s.id] && ( )} - {shortUrls[s.id] - ? - : - } + )} {!!s.is_active && (