modified: frontend/src/pages/ApiKeys.tsx
This commit is contained in:
@@ -56,9 +56,33 @@ export default function ApiKeys() {
|
||||
},
|
||||
});
|
||||
|
||||
const copyToClipboard = (key: string) => {
|
||||
navigator.clipboard.writeText(key);
|
||||
toast.success('API ключ скопирован в буфер обмена');
|
||||
const copyToClipboard = async (key: string) => {
|
||||
try {
|
||||
// Try modern clipboard API first (requires HTTPS or localhost)
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(key);
|
||||
toast.success('API ключ скопирован в буфер обмена');
|
||||
} else {
|
||||
// Fallback for HTTP
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = key;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-999999px';
|
||||
textArea.style.top = '-999999px';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
toast.success('API ключ скопирован в буфер обмена');
|
||||
} catch (err) {
|
||||
toast.error('Не удалось скопировать');
|
||||
}
|
||||
textArea.remove();
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error('Не удалось скопировать');
|
||||
}
|
||||
};
|
||||
|
||||
const toggleReveal = (id: string) => {
|
||||
|
||||
Reference in New Issue
Block a user