feat: remove Tools dropdown and redirect inference requests to local Golang backend on http://0.0.0.0:7777
This commit is contained in:
@@ -40,7 +40,6 @@
|
||||
{
|
||||
"label": { "en": "Tools", "hi": "टूल्स" },
|
||||
"href": "/tools",
|
||||
"hasDropdown": true,
|
||||
"badge": "61 tools"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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<string, React.ComponentType<{ className?: string }>> = {
|
||||
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<NodeJS.Timeout | null>(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 (
|
||||
<div
|
||||
key={link.href}
|
||||
className="relative"
|
||||
onMouseEnter={handleToolsMouseEnter}
|
||||
onMouseLeave={handleToolsMouseLeave}
|
||||
>
|
||||
<Link
|
||||
href={link.href}
|
||||
className={`relative px-3.5 py-1.5 rounded-full text-xs sm:text-sm font-body motion-safe:transition-[color,background-color,box-shadow] duration-150 flex items-center gap-1.5 ${
|
||||
active
|
||||
? 'bg-paper-hi text-ink font-medium shadow-xs border border-rule/80'
|
||||
: 'text-ink-2 hover:text-ink hover:bg-paper-hi/60'
|
||||
}`}
|
||||
>
|
||||
<span>{link.label}</span>
|
||||
<ChevronDown className={`w-3 h-3 text-muted transition-transform duration-200 ${
|
||||
toolsDropdownOpen ? 'rotate-180 text-accent' : ''
|
||||
}`} />
|
||||
</Link>
|
||||
|
||||
{/* Tools Dropdown Menu - Sleek, Clean & Professional (Text Only, No Icons) */}
|
||||
{toolsDropdownOpen && (
|
||||
<div
|
||||
className="absolute top-full left-1/2 -translate-x-1/2 pt-2.5 w-[280px] z-50 animate-in fade-in zoom-in-95 duration-150"
|
||||
>
|
||||
<div className="p-2 rounded-2xl bg-paper-hi border border-rule shadow-xl space-y-1">
|
||||
{/* Dynamic Categories List from JSON (Clean Typography, No Icons) */}
|
||||
<div className="space-y-0.5">
|
||||
{categories.map((cat) => {
|
||||
const catName = resolveLocalised(cat.name, currentLocale);
|
||||
const catDesc = resolveLocalised(cat.description, currentLocale);
|
||||
const catHref = `/tools#category-${cat.id}`;
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={cat.id}
|
||||
href={catHref}
|
||||
onClick={() => {
|
||||
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"
|
||||
>
|
||||
<span className="font-sans font-semibold text-xs text-ink group-hover/item:text-accent transition-colors block">
|
||||
{catName}
|
||||
</span>
|
||||
{catDesc && (
|
||||
<p className="text-[11px] text-muted font-sans line-clamp-1 mt-0.5 group-hover/item:text-slate-600 transition-colors">
|
||||
{catDesc}
|
||||
</p>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Clean Minimal Footer */}
|
||||
<div className="pt-2 mt-1 border-t border-rule/70 px-3.5 py-1">
|
||||
<Link
|
||||
href={link.href}
|
||||
onClick={() => 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"
|
||||
>
|
||||
<span>{viewAllText}</span>
|
||||
<ArrowRight className="w-3.5 h-3.5" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={link.href}
|
||||
@@ -300,32 +202,6 @@ export function Navbar({ config, currentLocale, categories = [], totalToolsCount
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
|
||||
{/* Sub-categories under Tools on mobile drawer (Clean Text Only, No Icons) */}
|
||||
{link.href === '/tools' && categories.length > 0 && (
|
||||
<div className="pl-3 pr-1 py-1 grid grid-cols-2 gap-1.5">
|
||||
{categories.map((cat) => {
|
||||
const catName = resolveLocalised(cat.name, currentLocale);
|
||||
const catHref = `/tools#category-${cat.id}`;
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={cat.id}
|
||||
href={catHref}
|
||||
onClick={() => {
|
||||
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"
|
||||
>
|
||||
<span className="truncate">{catName}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user