import React, { useState } from 'react'; import axios from 'axios'; import './ClientDownload.css'; const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:3001'; function ClientDownload({ onClose }) { const [serverId, setServerId] = useState(''); const [serverUrl, setServerUrl] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); // Get the base server URL for curl command (where the API is hosted) const getBaseUrl = () => { // Use serverUrl if provided, otherwise default to current origin but replace port 3000 with 3001 if (serverUrl) { return serverUrl; } return window.location.origin.replace(':3000', ':3001'); }; // Generate curl command const getCurlCommand = () => { const baseUrl = getBaseUrl(); // Include serverUrl query parameter if a custom serverUrl was provided const queryParam = serverUrl ? `?serverUrl=${encodeURIComponent(serverUrl)}` : ''; return `curl -s ${baseUrl}/api/download-client/${serverId}${queryParam} | bash`; }; const copyCurlCommand = () => { navigator.clipboard.writeText(getCurlCommand()); }; const handleDownload = async (e) => { e.preventDefault(); setLoading(true); setError(null); setSuccess(false); try { const response = await axios.post( `${API_URL}/api/download-client`, { serverId: serverId || `server-${Date.now()}`, serverUrl: serverUrl || window.location.origin.replace(':3000', ':3001') }, { responseType: 'blob' } ); // Create download link const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', `oculog-client-install.sh`); document.body.appendChild(link); link.click(); link.remove(); window.URL.revokeObjectURL(url); setSuccess(true); setTimeout(() => { setSuccess(false); if (onClose) onClose(); }, 3000); } catch (err) { setError(err.response?.data?.error || 'Failed to generate client package'); } finally { setLoading(false); } }; return (
Generate a pre-configured client installer for your Ubuntu server. The installer includes your server URL and API key automatically configured.
{/* Curl Installation Instructions */}Copy and paste this command directly into your Ubuntu server terminal:
{serverId ? getCurlCommand() : 'curl -s SERVER_URL/api/download-client/SERVER_ID?serverUrl=SERVER_URL | bash'}
{serverId && (
)}
Fill in the Server ID field above to generate your custom curl command. The command will automatically use your Server URL if provided.
chmod +x oculog-client-install.shsudo ./oculog-client-install.sh