Upload-Freigabe: Link-Button generiert automatisch Kurz-URL via is.gd
This commit is contained in:
@@ -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 }) {
|
||||
<div style={{display:'flex',gap:5,flexShrink:0}}>
|
||||
{!!s.is_active && !expired && (
|
||||
<>
|
||||
<button onClick={()=>copyLink(s.token)}
|
||||
<button onClick={()=>copyLink(s.id,s.token)}
|
||||
style={{...S.btn(copied===s.token?'#4ecdc4':'#ffe66d',copied!==s.token),fontSize:10,padding:'4px 10px'}}>
|
||||
{copied===s.token?'✓ Kopiert':'📋 Link'}
|
||||
{shortening===s.id?'…':copied===s.token?'✓ Kopiert':'📋 Link'}
|
||||
</button>
|
||||
{sharePws[s.id] && (
|
||||
<button onClick={()=>{ navigator.clipboard?.writeText(sharePws[s.id]).then(()=>toast('Passwort kopiert ✓')).catch(()=>toast(sharePws[s.id])); }}
|
||||
style={{...S.btn('#ffe66d',true),fontSize:10,padding:'4px 10px'}}>🔑 PW</button>
|
||||
)}
|
||||
{shortUrls[s.id]
|
||||
? <button onClick={()=>{ navigator.clipboard?.writeText(shortUrls[s.id]).then(()=>toast('Kurz-URL kopiert ✓')).catch(()=>{}); }}
|
||||
style={{...S.btn('#4ecdc4',true),fontSize:10,padding:'4px 10px'}}>🔗 Kurz</button>
|
||||
: <button onClick={()=>shorten(s.id,s.token)} disabled={shortening===s.id}
|
||||
style={{background:'rgba(255,255,255,0.05)',border:'1px solid rgba(255,255,255,0.15)',borderRadius:6,color:'rgba(255,255,255,0.5)',cursor:shortening===s.id?'default':'pointer',fontFamily:'monospace',fontSize:10,padding:'4px 10px'}}>
|
||||
{shortening===s.id?'…':'🔗↓'}
|
||||
</button>
|
||||
}
|
||||
|
||||
</>
|
||||
)}
|
||||
{!!s.is_active && (
|
||||
|
||||
Reference in New Issue
Block a user