Upload-Freigabe: Link-Button generiert automatisch Kurz-URL via is.gd
This commit is contained in:
@@ -220,33 +220,41 @@ function UploadShareManager({ toast }) {
|
|||||||
setShortening(null);
|
setShortening(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyLink = async (shareId, token) => {
|
const doCopy = (text) => {
|
||||||
// Wenn Kurz-URL vorhanden, die nehmen - sonst generieren
|
// Fallback-Kopieren ohne navigator.clipboard (funktioniert auch in PWA/mobile)
|
||||||
if (shortUrls[shareId]) {
|
if (navigator.clipboard) {
|
||||||
navigator.clipboard?.writeText(shortUrls[shareId]).catch(()=>{});
|
navigator.clipboard.writeText(text).catch(() => {
|
||||||
setCopied(token); setTimeout(()=>setCopied(null),2500);
|
const ta = document.createElement('textarea');
|
||||||
return;
|
ta.value = text; ta.style.cssText='position:fixed;opacity:0';
|
||||||
|
document.body.appendChild(ta); ta.focus(); ta.select();
|
||||||
|
document.execCommand('copy'); document.body.removeChild(ta);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const ta = document.createElement('textarea');
|
||||||
|
ta.value = text; ta.style.cssText='position:fixed;opacity:0';
|
||||||
|
document.body.appendChild(ta); ta.focus(); ta.select();
|
||||||
|
document.execCommand('copy'); document.body.removeChild(ta);
|
||||||
}
|
}
|
||||||
// Kurz-URL erst generieren
|
};
|
||||||
setShortening(shareId);
|
|
||||||
const url = `${window.location.origin}/u/${token}`;
|
const copyLink = (shareId, token) => {
|
||||||
try {
|
// SOFORT kopieren (synchron, innerhalb User-Gesture-Kontext)
|
||||||
const r = await fetch(`https://is.gd/create.php?format=simple&url=${encodeURIComponent(url)}`);
|
const url = shortUrls[shareId] || `${window.location.origin}/u/${token}`;
|
||||||
const short = await r.text();
|
doCopy(url);
|
||||||
if (short.startsWith('http')) {
|
setCopied(token); setTimeout(()=>setCopied(null), 2500);
|
||||||
setShortUrls(p=>({...p,[shareId]:short.trim()}));
|
|
||||||
navigator.clipboard?.writeText(short.trim()).catch(()=>{});
|
// Falls noch keine Kurz-URL: im Hintergrund generieren (für nächsten Klick)
|
||||||
setCopied(token); setTimeout(()=>setCopied(null),2500);
|
if (!shortUrls[shareId] && shortening !== shareId) {
|
||||||
} else {
|
setShortening(shareId);
|
||||||
// Fallback auf Original-URL
|
const fullUrl = `${window.location.origin}/u/${token}`;
|
||||||
navigator.clipboard?.writeText(url).catch(()=>{});
|
fetch(`https://is.gd/create.php?format=simple&url=${encodeURIComponent(fullUrl)}`)
|
||||||
setCopied(token); setTimeout(()=>setCopied(null),2500);
|
.then(r => r.text())
|
||||||
}
|
.then(short => {
|
||||||
} catch {
|
if (short.startsWith('http')) setShortUrls(p=>({...p,[shareId]:short.trim()}));
|
||||||
navigator.clipboard?.writeText(url).catch(()=>{});
|
})
|
||||||
setCopied(token); setTimeout(()=>setCopied(null),2500);
|
.catch(()=>{})
|
||||||
|
.finally(()=>setShortening(null));
|
||||||
}
|
}
|
||||||
setShortening(null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadLogs = () => {
|
const loadLogs = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user