UNPKG

buroventures-harald-code

Version:

Harald Code - AI-powered coding assistant CLI

80 lines 4.02 kB
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime"; /** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { useState, useEffect } from 'react'; import { Box, Text } from 'ink'; import { Colors } from '../colors.js'; import * as fs from 'fs'; import * as path from 'path'; import { homedir } from 'os'; const SPONSOR_API_URL = 'https://n8n2.buroventures.com/webhook/9092e80b-f69c-4850-a83b-d38f01f1ae8a'; const CACHE_FILE = path.join(homedir(), '.qwen', 'sponsor-cache.json'); const CACHE_DURATION = 60 * 60 * 1000; // 1 hour in milliseconds export const SponsorSection = () => { const [sponsor, setSponsor] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchSponsor = async () => { try { // Check cache first if (fs.existsSync(CACHE_FILE)) { const cached = fs.readFileSync(CACHE_FILE, 'utf-8'); const { data, timestamp } = JSON.parse(cached); if (Date.now() - timestamp < CACHE_DURATION) { setSponsor(data); setLoading(false); return; } } // Fetch from API const response = await fetch(SPONSOR_API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', }, // Empty body for POST request body: JSON.stringify({}), }); if (response.ok) { const data = await response.json(); console.debug('Sponsor API response:', data); setSponsor(data); // Cache the response const cacheDir = path.dirname(CACHE_FILE); if (!fs.existsSync(cacheDir)) { fs.mkdirSync(cacheDir, { recursive: true }); } const cacheData = { data, timestamp: Date.now(), }; fs.writeFileSync(CACHE_FILE, JSON.stringify(cacheData)); } else { console.debug('Sponsor API failed with status:', response.status); } } catch (error) { // Silently fail - will show fallback message console.debug('Failed to fetch sponsor data:', error); } finally { setLoading(false); } }; fetchSponsor(); }, []); if (loading) { // Show fallback immediately instead of waiting return (_jsxs(Box, { justifyContent: "center", marginTop: 1, children: [_jsxs(Text, { color: Colors.Gray, children: ["\uD83D\uDC8E Sponsor this CLI and show your name here:", ' '] }), _jsx(Text, { color: Colors.AccentBlue, children: "/sponsor apply" })] })); } if (sponsor) { return (_jsxs(Box, { justifyContent: "space-between", marginTop: 1, width: "100%", children: [_jsxs(Box, { children: [_jsxs(Text, { color: Colors.Gray, children: ["\uD83D\uDC8E Sponsored by:", ' '] }), _jsx(Text, { color: Colors.AccentBlue, underline: true, children: sponsor.Name }), _jsxs(Text, { color: Colors.Gray, children: [' ', "(", sponsor.url, ")"] })] }), _jsxs(Box, { children: [_jsxs(Text, { color: Colors.Gray, children: ["Want to sponsor next?", ' '] }), _jsx(Text, { color: Colors.AccentBlue, children: "/sponsor apply" })] })] })); } // Fallback message when no sponsor return (_jsxs(Box, { justifyContent: "center", marginTop: 1, children: [_jsxs(Text, { color: Colors.Gray, children: ["\uD83D\uDC8E Sponsor this CLI and show your name here:", ' '] }), _jsx(Text, { color: Colors.AccentBlue, children: "/sponsor apply" })] })); }; //# sourceMappingURL=SponsorDisplay.js.map