From 8f4e7913fb78bc43d03f3e1cd04447cca246c261 Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Wed, 11 Nov 2026 17:08:24 +0530 Subject: [PATCH] feat: remove Tools dropdown and redirect inference requests to local Golang backend on http://0.0.0.0:7777 --- content/site.config.json | 1 - src/components/ui/Navbar.tsx | 124 ---------------------------------- src/lib/api/requestBuilder.ts | 28 ++++++-- 3 files changed, 23 insertions(+), 130 deletions(-) diff --git a/content/site.config.json b/content/site.config.json index 613b25e..8e5bfb5 100644 --- a/content/site.config.json +++ b/content/site.config.json @@ -40,7 +40,6 @@ { "label": { "en": "Tools", "hi": "टूल्स" }, "href": "/tools", - "hasDropdown": true, "badge": "61 tools" }, { diff --git a/src/components/ui/Navbar.tsx b/src/components/ui/Navbar.tsx index ea9a05b..cee5bcc 100644 --- a/src/components/ui/Navbar.tsx +++ b/src/components/ui/Navbar.tsx @@ -15,8 +15,6 @@ import { Scissors, Palette, Wand2, - ChevronDown, - ChevronRight, Home } from 'lucide-react'; import { SiteConfig, CategoryItem, resolveLocalised } from '@/types'; @@ -44,22 +42,8 @@ const ICON_MAP: Record> = { export function Navbar({ config, currentLocale, categories = [], totalToolsCount }: NavbarProps) { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [scrolled, setScrolled] = useState(false); - const [toolsDropdownOpen, setToolsDropdownOpen] = useState(false); - const toolsTimeoutRef = useRef(null); const pathname = usePathname(); - const handleToolsMouseEnter = () => { - if (toolsTimeoutRef.current) clearTimeout(toolsTimeoutRef.current); - setToolsDropdownOpen(true); - }; - - const handleToolsMouseLeave = () => { - if (toolsTimeoutRef.current) clearTimeout(toolsTimeoutRef.current); - toolsTimeoutRef.current = setTimeout(() => { - setToolsDropdownOpen(false); - }, 180); - }; - // Detect scroll to slightly elevate glass opacity useEffect(() => { const handleScroll = () => { @@ -100,7 +84,6 @@ export function Navbar({ config, currentLocale, categories = [], totalToolsCount href: item.href, label: resolveLocalised(item.label, currentLocale), badge: item.badge, - hasDropdown: item.hasDropdown ?? (item.href === '/tools'), exact: item.href === '/', })); @@ -111,9 +94,6 @@ export function Navbar({ config, currentLocale, categories = [], totalToolsCount const ctaLabel = resolveLocalised(config.nav?.cta?.label, currentLocale) || 'Try tools for free'; const ctaHref = config.nav?.cta?.href || '/tools'; - const viewAllText = config.nav?.toolsDropdown?.viewAllText - ? resolveLocalised(config.nav.toolsDropdown.viewAllText, currentLocale) - : `Explore all ${totalToolsCount || ''} studio tools`; const dropdownTagline = config.nav?.toolsDropdown?.tagline ? resolveLocalised(config.nav.toolsDropdown.tagline, currentLocale) : 'Instant client GPU trial · Zero retention'; @@ -140,84 +120,6 @@ export function Navbar({ config, currentLocale, categories = [], totalToolsCount {navLinks.map((link) => { const active = isLinkActive(link.href, link.exact); - if (link.hasDropdown) { - return ( -
- - {link.label} - - - - {/* Tools Dropdown Menu - Sleek, Clean & Professional (Text Only, No Icons) */} - {toolsDropdownOpen && ( -
-
- {/* Dynamic Categories List from JSON (Clean Typography, No Icons) */} -
- {categories.map((cat) => { - const catName = resolveLocalised(cat.name, currentLocale); - const catDesc = resolveLocalised(cat.description, currentLocale); - const catHref = `/tools#category-${cat.id}`; - - return ( - { - setToolsDropdownOpen(false); - if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) { - window.location.hash = `category-${cat.id}`; - } - }} - className="group/item block px-3.5 py-2.5 rounded-xl hover:bg-paper-2 transition-all duration-150" - > - - {catName} - - {catDesc && ( -

- {catDesc} -

- )} - - ); - })} -
- - {/* Clean Minimal Footer */} -
- setToolsDropdownOpen(false)} - className="text-xs font-sans font-semibold text-accent hover:text-accent-hi inline-flex items-center justify-between w-full transition-colors py-1" - > - {viewAllText} - - -
-
-
- )} -
- ); - } - return ( )} - - {/* Sub-categories under Tools on mobile drawer (Clean Text Only, No Icons) */} - {link.href === '/tools' && categories.length > 0 && ( -
- {categories.map((cat) => { - const catName = resolveLocalised(cat.name, currentLocale); - const catHref = `/tools#category-${cat.id}`; - - return ( - { - setMobileMenuOpen(false); - if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) { - window.location.hash = `category-${cat.id}`; - } - }} - className="p-2.5 rounded-xl text-xs text-ink hover:text-accent hover:bg-paper-2 bg-paper-hi/60 border border-rule font-sans font-medium transition-colors text-center" - > - {catName} - - ); - })} -
- )} ); })} diff --git a/src/lib/api/requestBuilder.ts b/src/lib/api/requestBuilder.ts index 68176e7..b11b56e 100644 --- a/src/lib/api/requestBuilder.ts +++ b/src/lib/api/requestBuilder.ts @@ -83,8 +83,8 @@ export async function executeBackendTryIt( } } - // Allow overriding base host via env (e.g. if running FastAPI on localhost:6666) - const envBackendUrl = process.env.API_BACKEND_URL; + // Allow overriding base host via env (default to local Golang backend server at http://0.0.0.0:7777) + const envBackendUrl = process.env.API_BACKEND_URL || 'http://0.0.0.0:7777'; if (envBackendUrl) { try { const parsed = new URL(targetUrl); @@ -101,10 +101,10 @@ export async function executeBackendTryIt( const formData = new FormData(); const blob = new Blob([new Uint8Array(imageBuffer)]); - // Find primary file parameter name (e.g. 'image', 'image0', 'original_image') + // Find primary file parameter name (e.g. 'image0', 'image', 'original_image') const fileParam = endpoint.params.find( (p) => p.kind === 'file' && !p.name.toLowerCase().includes('mask') && !p.name.toLowerCase().includes('ref') - ) || { name: 'image' }; + ) || { name: 'image0' }; formData.append(fileParam.name, blob, filename); // If mask buffer provided (Inpainting / Custom Mask / Auto Mask) @@ -172,10 +172,28 @@ export async function executeBackendTryIt( return await generateMockNeuralResult(imageBuffer, toolId, variantId); } - const contentType = response.headers.get('content-type') || endpoint.responseType || 'image/jpeg'; const arrayBuf = await response.arrayBuffer(); const resultBuffer = Buffer.from(arrayBuf); + // Validate if the response is actually an image or a JSON error + const sig = checkFileSignature(resultBuffer); + if (!sig.valid) { + try { + const textPayload = resultBuffer.toString('utf8'); + if (textPayload.startsWith('{') || textPayload.startsWith('[')) { + const jsonResp = JSON.parse(textPayload); + console.warn(`[Backend API] Non-image payload from ${targetUrl}:`, jsonResp); + if (jsonResp.error || jsonResp.message || jsonResp.status === false || jsonResp.status === 'error') { + return await generateMockNeuralResult(imageBuffer, toolId, variantId); + } + } + } catch { + // Fallback + } + } + + const contentType = sig.valid && sig.mime ? sig.mime : (response.headers.get('content-type') || endpoint.responseType || 'image/jpeg'); + recordEndpointSuccess(endpoint.id); return { buffer: resultBuffer,