feat: complete dynamic JSON-driven photo tools frontend connected to FastAPI backend
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { normaliseCatalog } from '@/lib/catalog/loader';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const { endpoints, diff } = normaliseCatalog();
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
timestamp: new Date().toISOString(),
|
||||
totalEndpoints: endpoints.length,
|
||||
diff,
|
||||
});
|
||||
} catch (err: any) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: err.message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return POST();
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getToolById, getToolBySlug } from '@/lib/config/loader';
|
||||
import { getEndpointById } from '@/lib/catalog/loader';
|
||||
import { checkRateLimits, recordUsage } from '@/lib/api/rateLimiter';
|
||||
import { checkFileSignature, executeBackendTryIt, isCircuitOpen } from '@/lib/api/requestBuilder';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const maxDuration = 60; // 60 seconds request timeout per PRD §4.1
|
||||
|
||||
export async function POST(req: NextRequest, { params }: { params: { toolId: string } }) {
|
||||
const toolIdentifier = params.toolId;
|
||||
const tool = getToolById(toolIdentifier) || getToolBySlug(toolIdentifier);
|
||||
|
||||
if (!tool) {
|
||||
return NextResponse.json(
|
||||
{ state: 'failed', error: { code: 'TOOL_NOT_FOUND', messageKey: 'toolNotFound', retryable: false } },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!tool.tryIt || !tool.tryIt.enabled) {
|
||||
return NextResponse.json(
|
||||
{ state: 'unavailable', messageKey: 'toolUnavailable' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
const endpointId = tool.tryIt.endpointRef?.id;
|
||||
const endpoint = endpointId ? getEndpointById(endpointId) : undefined;
|
||||
|
||||
if (!endpoint || !endpoint.enabled || !endpoint.publicTry || isCircuitOpen(endpoint.id)) {
|
||||
return NextResponse.json(
|
||||
{ state: 'unavailable', messageKey: 'toolTemporarilyUnavailable' },
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
// Rate Limiting & Abuse Prevention
|
||||
const ip = req.headers.get('x-forwarded-for')?.split(',')[0].trim() || '127.0.0.1';
|
||||
let visitorId = req.cookies.get('photoai_vid')?.value;
|
||||
let isNewVisitor = false;
|
||||
if (!visitorId) {
|
||||
visitorId = 'v_' + Math.random().toString(36).substring(2, 15);
|
||||
isNewVisitor = true;
|
||||
}
|
||||
|
||||
const rateCheck = checkRateLimits(visitorId, ip);
|
||||
if (!rateCheck.allowed) {
|
||||
const res = NextResponse.json(
|
||||
{
|
||||
state: 'limit',
|
||||
messageKey: rateCheck.reason === 'budget_exhausted' ? 'dailyBudgetExceeded' : 'freeTriesExhausted',
|
||||
remainingToday: 0,
|
||||
},
|
||||
{ status: 429 }
|
||||
);
|
||||
if (isNewVisitor) {
|
||||
res.cookies.set('photoai_vid', visitorId, { path: '/', maxAge: 60 * 60 * 24 * 30, httpOnly: true });
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
try {
|
||||
const formData = await req.formData();
|
||||
const file = formData.get('image') as File | null;
|
||||
const variantId = (formData.get('variant') as string) || tool.tryIt.endpointRef?.defaultVariant;
|
||||
const optionsRaw = formData.get('options') as string | null;
|
||||
let options: Record<string, any> = {};
|
||||
if (optionsRaw) {
|
||||
try {
|
||||
options = JSON.parse(optionsRaw);
|
||||
} catch {
|
||||
// Ignore malformed options
|
||||
}
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
return NextResponse.json(
|
||||
{ state: 'failed', error: { code: 'NO_IMAGE', messageKey: 'noImageProvided', retryable: false } },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Size limit check
|
||||
const maxBytes = (tool.tryIt.limits?.maxMB || 12) * 1024 * 1024;
|
||||
if (file.size > maxBytes) {
|
||||
return NextResponse.json(
|
||||
{ state: 'failed', error: { code: 'FILE_TOO_LARGE', messageKey: 'fileTooLarge', retryable: false } },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
|
||||
// File signature verification (JPEG, PNG, WEBP)
|
||||
const sigCheck = checkFileSignature(buffer);
|
||||
if (!sigCheck.valid) {
|
||||
return NextResponse.json(
|
||||
{ state: 'failed', error: { code: 'INVALID_SIGNATURE', messageKey: 'invalidFileType', retryable: false } },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Record rate-limit usage
|
||||
recordUsage(visitorId, ip);
|
||||
|
||||
// Call backend or mock engine
|
||||
const { buffer: resultBuffer, contentType } = await executeBackendTryIt(
|
||||
endpoint,
|
||||
tool.id,
|
||||
variantId,
|
||||
buffer,
|
||||
file.name || 'image.jpg',
|
||||
options
|
||||
);
|
||||
|
||||
const response = new NextResponse(new Uint8Array(resultBuffer), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
'Content-Length': resultBuffer.length.toString(),
|
||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||
'X-Remaining-Tries': rateCheck.remainingToday.toString(),
|
||||
},
|
||||
});
|
||||
|
||||
if (isNewVisitor) {
|
||||
response.cookies.set('photoai_vid', visitorId, { path: '/', maxAge: 60 * 60 * 24 * 30, httpOnly: true });
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err: any) {
|
||||
console.error(`[API /try/${toolIdentifier}] Error:`, err);
|
||||
return NextResponse.json(
|
||||
{
|
||||
state: 'failed',
|
||||
error: {
|
||||
code: 'PROCESSING_ERROR',
|
||||
messageKey: 'processingError',
|
||||
message: err.message || 'Internal processing error',
|
||||
retryable: true,
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { getAllApps, getAppBySlug, getAllTools, getTemplate } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { resolveLocalised } from '@/types';
|
||||
|
||||
interface AppPageProps {
|
||||
params: { slug: string };
|
||||
}
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const apps = getAllApps();
|
||||
return apps.map((a) => ({ slug: a.slug }));
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: AppPageProps): Promise<Metadata> {
|
||||
const app = getAppBySlug(params.slug);
|
||||
if (!app) return {};
|
||||
|
||||
const name = resolveLocalised(app.name, 'en');
|
||||
const tagline = resolveLocalised(app.tagline, 'en');
|
||||
|
||||
return {
|
||||
title: `${name} | Official Mobile App Download`,
|
||||
description: tagline,
|
||||
alternates: {
|
||||
canonical: `/apps/${app.slug}`,
|
||||
},
|
||||
openGraph: {
|
||||
title: `${name} — AI Photo Editing App`,
|
||||
description: tagline,
|
||||
type: 'website',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function AppDetailPage({ params }: AppPageProps) {
|
||||
const app = getAppBySlug(params.slug);
|
||||
if (!app) notFound();
|
||||
|
||||
const template = getTemplate('app') || { sections: [] };
|
||||
const allTools = getAllTools();
|
||||
const appTools = allTools.filter((t) => app.tools.includes(t.id));
|
||||
|
||||
const context = {
|
||||
app,
|
||||
tools: appTools,
|
||||
locale: 'en',
|
||||
};
|
||||
|
||||
// Structured Data (JSON-LD) per PRD §10 SEO-07
|
||||
const structuredData = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'SoftwareApplication',
|
||||
name: resolveLocalised(app.name, 'en'),
|
||||
operatingSystem: 'ANDROID, IOS',
|
||||
applicationCategory: 'MultimediaApplication',
|
||||
aggregateRating: {
|
||||
'@type': 'AggregateRating',
|
||||
ratingValue: app.rating.value.toString(),
|
||||
ratingCount: app.rating.count.toString(),
|
||||
},
|
||||
offers: {
|
||||
'@type': 'Offer',
|
||||
price: '0',
|
||||
priceCurrency: 'USD',
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
|
||||
/>
|
||||
{template.sections.map((section: any) => (
|
||||
<SectionRenderer key={section.id} section={section} context={context} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Metadata } from 'next';
|
||||
import { getPageConfig, getAllApps, getAllTools } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Dedicated Mobile Apps Suite | Android & iOS | Ekagni PhotoAI',
|
||||
description: 'Download our suite of AI photo editing apps for Android and iOS. Built with hardware-accelerated neural networks and 4K lossless export.',
|
||||
};
|
||||
|
||||
export default function AppsIndexPage() {
|
||||
const page = getPageConfig('apps');
|
||||
if (!page) notFound();
|
||||
|
||||
const apps = getAllApps();
|
||||
const tools = getAllTools();
|
||||
|
||||
const context = {
|
||||
page,
|
||||
apps,
|
||||
tools,
|
||||
locale: 'en',
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={context} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { RefreshCw, CheckCircle2, AlertTriangle, ShieldCheck, Database, Layers, ArrowRight } from 'lucide-react';
|
||||
import { EndpointSpec, DiffReport } from '@/types';
|
||||
|
||||
export default function CatalogManagerPage() {
|
||||
const [endpoints, setEndpoints] = useState<EndpointSpec[]>([]);
|
||||
const [diff, setDiff] = useState<DiffReport | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [reloading, setReloading] = useState(false);
|
||||
const [selectedEndpoint, setSelectedEndpoint] = useState<EndpointSpec | null>(null);
|
||||
|
||||
const fetchCatalog = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch('/api/catalog/reload', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
setDiff(data.diff);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchCatalog();
|
||||
}, []);
|
||||
|
||||
const triggerReload = async () => {
|
||||
setReloading(true);
|
||||
try {
|
||||
const res = await fetch('/api/catalog/reload', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
setDiff(data.diff);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
setReloading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
||||
{/* Top Banner */}
|
||||
<div className="flex flex-col md:flex-row items-start md:items-center justify-between gap-4 pb-8 border-b border-slate-200 dark:border-slate-800">
|
||||
<div>
|
||||
<div className="inline-flex items-center space-x-2 px-3 py-1 rounded-full bg-blue-50 dark:bg-blue-950 text-blue-600 dark:text-blue-400 text-xs font-semibold mb-2">
|
||||
<Database className="w-3.5 h-3.5" />
|
||||
<span>Catalogue-Driven API Engine (PRD §7)</span>
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold text-slate-900 dark:text-white">
|
||||
Backend API Catalogue Inspector
|
||||
</h1>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
|
||||
Real-time reflection of FastAPI endpoints, overlays, parameters, variants, and snapshot diffs.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={triggerReload}
|
||||
disabled={reloading}
|
||||
className="inline-flex items-center space-x-2 px-5 py-2.5 rounded-xl text-sm font-semibold text-white bg-blue-600 hover:bg-blue-700 shadow-md shadow-blue-500/20 disabled:opacity-50 transition-all active:scale-95"
|
||||
>
|
||||
<RefreshCw className={`w-4 h-4 ${reloading ? 'animate-spin' : ''}`} />
|
||||
<span>Reload & Diff Snapshot</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Snapshot Diff Card */}
|
||||
{diff && (
|
||||
<div className="my-8 p-6 rounded-2xl bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-800 shadow-sm grid grid-cols-2 sm:grid-cols-4 gap-4">
|
||||
<div className="space-y-1">
|
||||
<p className="text-xs font-medium text-slate-500">Total Active Endpoints</p>
|
||||
<p className="text-2xl font-bold text-slate-900 dark:text-white">{diff.totalEndpoints}</p>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<p className="text-xs font-medium text-slate-500">Added Endpoints</p>
|
||||
<p className="text-2xl font-bold text-emerald-600">{diff.addedEndpointIds.length}</p>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<p className="text-xs font-medium text-slate-500">Changed Endpoints</p>
|
||||
<p className="text-2xl font-bold text-blue-600">{diff.changedEndpointIds.length}</p>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<p className="text-xs font-medium text-slate-500">Misconfigured</p>
|
||||
<p className="text-2xl font-bold text-amber-600">{diff.misconfiguredEndpoints.length}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Key Architectural Guarantees */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-10">
|
||||
<div className="p-5 rounded-2xl bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 space-y-2">
|
||||
<div className="flex items-center space-x-2 text-emerald-600 font-semibold text-sm">
|
||||
<ShieldCheck className="w-4 h-4" />
|
||||
<span>Zero Secret Leakage</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-600 dark:text-slate-400">
|
||||
Secrets and authentication keys stay server-side only. Browser calls exclusively talk to <code>/api/try/*</code>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="p-5 rounded-2xl bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 space-y-2">
|
||||
<div className="flex items-center space-x-2 text-blue-600 font-semibold text-sm">
|
||||
<Layers className="w-4 h-4" />
|
||||
<span>Two-Layer Decoupling</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-600 dark:text-slate-400">
|
||||
FastAPI owner edits <code>api.catalog.json</code> anytime. Website settings live independently in <code>api.overlay.json</code>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="p-5 rounded-2xl bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 space-y-2">
|
||||
<div className="flex items-center space-x-2 text-indigo-600 font-semibold text-sm">
|
||||
<CheckCircle2 className="w-4 h-4" />
|
||||
<span>Graceful Degradation</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-600 dark:text-slate-400">
|
||||
Missing or invalid catalogue endpoints automatically flag tools as unavailable without taking down the website.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--color-primary: #2563EB;
|
||||
--color-primary-hover: #1D4ED8;
|
||||
--color-primary-light: #EFF6FF;
|
||||
--color-primary-dark: #1E40AF;
|
||||
--color-accent: #0E9F9A;
|
||||
--color-accent-hover: #0B7F7B;
|
||||
--color-accent-light: #F0FDF4;
|
||||
--color-surface: #FFFFFF;
|
||||
--color-surface-subtle: #F8FAFC;
|
||||
--color-surface-dark: #0F172A;
|
||||
--color-surface-dark-subtle: #1E293B;
|
||||
--theme-radius: 12px;
|
||||
--theme-max-width: 1280px;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--color-surface: #0B1220;
|
||||
--color-surface-subtle: #0F172A;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #0F1F3D;
|
||||
background-color: #FFFFFF;
|
||||
font-family: Inter, system-ui, -apple-system, sans-serif;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.dark body {
|
||||
color: #E5E9F2;
|
||||
background-color: #0B1220;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAppBySlug, getAppById, getToolBySlug, getToolById } from '@/lib/config/loader';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { tool: string; app: string } }
|
||||
) {
|
||||
const tool = getToolBySlug(params.tool) || getToolById(params.tool);
|
||||
const app = getAppBySlug(params.app) || getAppById(params.app);
|
||||
|
||||
if (!app) {
|
||||
return NextResponse.redirect(new URL('/apps', req.url));
|
||||
}
|
||||
|
||||
const userAgent = req.headers.get('user-agent') || '';
|
||||
const isAndroid = /android/i.test(userAgent);
|
||||
const isIOS = /ipad|iphone|ipod/i.test(userAgent);
|
||||
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const source = searchParams.get('utm_source') || 'web_try';
|
||||
const campaign = searchParams.get('utm_campaign') || (tool ? tool.slug : 'general');
|
||||
const promo = searchParams.get('promo') || (app.welcomeBonus ? app.welcomeBonus.code : 'TRYWEB50');
|
||||
|
||||
if (isAndroid) {
|
||||
const playUrl = app.stores.android?.url || 'https://play.google.com';
|
||||
const finalUrl = new URL(playUrl);
|
||||
finalUrl.searchParams.set('referrer', `utm_source=${source}&utm_campaign=${campaign}&promo=${promo}`);
|
||||
return NextResponse.redirect(finalUrl.toString());
|
||||
}
|
||||
|
||||
if (isIOS) {
|
||||
const iosUrl = app.stores.ios?.url || 'https://apps.apple.com';
|
||||
const finalUrl = new URL(iosUrl);
|
||||
finalUrl.searchParams.set('pt', '123456');
|
||||
finalUrl.searchParams.set('ct', `${source}_${campaign}`);
|
||||
return NextResponse.redirect(finalUrl.toString());
|
||||
}
|
||||
|
||||
// Desktop visitor -> Redirect to app page with QR code & deep link info
|
||||
const desktopUrl = new URL(`/apps/${app.slug}`, req.url);
|
||||
desktopUrl.searchParams.set('src', source);
|
||||
desktopUrl.searchParams.set('tool', tool ? tool.slug : '');
|
||||
desktopUrl.searchParams.set('promo', promo);
|
||||
return NextResponse.redirect(desktopUrl.toString());
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { Inter } from 'next/font/google';
|
||||
import './globals.css';
|
||||
import { getSiteConfig } from '@/lib/config/loader';
|
||||
import { Navbar } from '@/components/ui/Navbar';
|
||||
import { Footer } from '@/components/ui/Footer';
|
||||
|
||||
const inter = Inter({ subsets: ['latin'], variable: '--font-inter' });
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const config = getSiteConfig();
|
||||
return {
|
||||
title: {
|
||||
default: config.brand.name + ' | AI Photo Tools',
|
||||
template: config.seo.titleTemplate || `%s | ${config.brand.name}`,
|
||||
},
|
||||
description: typeof config.brand.tagline === 'string' ? config.brand.tagline : config.brand.tagline.en,
|
||||
metadataBase: new URL(config.seo.siteUrl || 'http://localhost:3000'),
|
||||
openGraph: {
|
||||
type: 'website',
|
||||
siteName: config.brand.name,
|
||||
images: [{ url: config.seo.defaultOgImage || '/brand/og-default.png' }],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const config = getSiteConfig();
|
||||
|
||||
return (
|
||||
<html lang="en" className={inter.variable}>
|
||||
<body className="min-h-screen flex flex-col antialiased selection:bg-blue-500 selection:text-white">
|
||||
<Navbar config={config} currentLocale="en" />
|
||||
<main className="flex-1">{children}</main>
|
||||
<Footer config={config} currentLocale="en" />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { getPageConfig, getAllTools, getAllApps, getAllCategories, getToolById, getAppById } from '@/lib/config/loader';
|
||||
import { getEndpointById } from '@/lib/catalog/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const revalidate = 600; // ISR 10 minutes fallback per PRD §4.2
|
||||
|
||||
export default function HomePage() {
|
||||
const page = getPageConfig('home');
|
||||
if (!page) notFound();
|
||||
|
||||
const tools = getAllTools();
|
||||
const apps = getAllApps();
|
||||
const categories = getAllCategories();
|
||||
|
||||
// Find hero tool and variants
|
||||
const heroTool = getToolById('face.blemish.remove') || tools[0];
|
||||
const heroApp = heroTool ? getAppById(heroTool.homeApp) : null;
|
||||
const endpoint = heroTool?.tryIt?.endpointRef?.id ? getEndpointById(heroTool.tryIt.endpointRef.id) : undefined;
|
||||
const variants = endpoint?.variants || [];
|
||||
|
||||
const context = {
|
||||
page,
|
||||
tools,
|
||||
apps,
|
||||
categories,
|
||||
tool: heroTool,
|
||||
homeApp: heroApp,
|
||||
variants,
|
||||
locale: 'en',
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={context} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Metadata } from 'next';
|
||||
import { getPageConfig, getAllApps } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Pricing & In-App Purchases | Ekagni PhotoAI',
|
||||
description: 'Understand how free web tries and app-specific pricing work. No cross-app subscriptions or web wallets.',
|
||||
};
|
||||
|
||||
export default function PricingPage() {
|
||||
const page = getPageConfig('pricing');
|
||||
if (!page) notFound();
|
||||
|
||||
const apps = getAllApps();
|
||||
const context = { page, apps, locale: 'en' };
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={context} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Metadata } from 'next';
|
||||
import { getPageConfig } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Privacy Policy | Ekagni PhotoAI',
|
||||
description: 'Full privacy policy: transient image handling, zero retention, and GDPR compliance.',
|
||||
};
|
||||
|
||||
export default function PrivacyPage() {
|
||||
const page = getPageConfig('privacy');
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={{ page, locale: 'en' }} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { MetadataRoute } from 'next';
|
||||
|
||||
export default function robots(): MetadataRoute.Robots {
|
||||
const baseUrl = process.env.SITE_URL || 'http://localhost:3000';
|
||||
|
||||
return {
|
||||
rules: {
|
||||
userAgent: '*',
|
||||
allow: '/',
|
||||
disallow: ['/api/', '/go/', '/catalog-manager'],
|
||||
},
|
||||
sitemap: `${baseUrl}/sitemap.xml`,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { MetadataRoute } from 'next';
|
||||
import { getAllTools, getAllApps } from '@/lib/config/loader';
|
||||
|
||||
export default function sitemap(): MetadataRoute.Sitemap {
|
||||
const baseUrl = process.env.SITE_URL || 'http://localhost:3000';
|
||||
const now = new Date();
|
||||
|
||||
const staticPages = [
|
||||
'',
|
||||
'/tools',
|
||||
'/apps',
|
||||
'/pricing',
|
||||
'/trust',
|
||||
'/privacy',
|
||||
'/terms',
|
||||
].map((route) => ({
|
||||
url: `${baseUrl}${route}`,
|
||||
lastModified: now,
|
||||
changeFrequency: 'daily' as const,
|
||||
priority: route === '' ? 1.0 : 0.8,
|
||||
}));
|
||||
|
||||
const tools = getAllTools().map((t) => ({
|
||||
url: `${baseUrl}/tools/${t.slug}`,
|
||||
lastModified: now,
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.9,
|
||||
}));
|
||||
|
||||
const apps = getAllApps().map((a) => ({
|
||||
url: `${baseUrl}/apps/${a.slug}`,
|
||||
lastModified: now,
|
||||
changeFrequency: 'weekly' as const,
|
||||
priority: 0.8,
|
||||
}));
|
||||
|
||||
return [...staticPages, ...tools, ...apps];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Metadata } from 'next';
|
||||
import { getPageConfig } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Terms of Service | Ekagni PhotoAI',
|
||||
description: 'Terms of Service for online web tools and mobile app handoff.',
|
||||
};
|
||||
|
||||
export default function TermsPage() {
|
||||
const page = getPageConfig('terms');
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={{ page, locale: 'en' }} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { getAllTools, getToolBySlug, getAppById, getTemplate } from '@/lib/config/loader';
|
||||
import { getEndpointById } from '@/lib/catalog/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { resolveLocalised } from '@/types';
|
||||
|
||||
interface ToolPageProps {
|
||||
params: { slug: string };
|
||||
}
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const tools = getAllTools();
|
||||
return tools.map((t) => ({ slug: t.slug }));
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: ToolPageProps): Promise<Metadata> {
|
||||
const tool = getToolBySlug(params.slug);
|
||||
if (!tool) return {};
|
||||
|
||||
const name = resolveLocalised(tool.name, 'en');
|
||||
const summary = resolveLocalised(tool.summary, 'en');
|
||||
|
||||
return {
|
||||
title: tool.seo?.title || `${name} Free Online | Ekagni PhotoAI`,
|
||||
description: tool.seo?.description || summary,
|
||||
alternates: {
|
||||
canonical: `/tools/${tool.slug}`,
|
||||
},
|
||||
openGraph: {
|
||||
title: `${name} Free Online`,
|
||||
description: summary,
|
||||
type: 'website',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function ToolDetailPage({ params }: ToolPageProps) {
|
||||
const tool = getToolBySlug(params.slug);
|
||||
if (!tool) notFound();
|
||||
|
||||
const homeApp = getAppById(tool.homeApp);
|
||||
const template = getTemplate('tool') || { sections: [] };
|
||||
|
||||
const endpoint = tool.tryIt?.endpointRef?.id ? getEndpointById(tool.tryIt.endpointRef.id) : undefined;
|
||||
const variants = endpoint?.variants || [];
|
||||
|
||||
// Related tools
|
||||
const allTools = getAllTools();
|
||||
const relatedTools = (tool.related || [])
|
||||
.map((rId) => allTools.find((t) => t.id === rId))
|
||||
.filter(Boolean) as any[];
|
||||
|
||||
const context = {
|
||||
tool,
|
||||
homeApp,
|
||||
variants,
|
||||
tools: allTools,
|
||||
relatedTools,
|
||||
locale: 'en',
|
||||
};
|
||||
|
||||
// Structured Data (JSON-LD) per PRD §10 SEO-07
|
||||
const structuredData = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'WebApplication',
|
||||
name: resolveLocalised(tool.name, 'en'),
|
||||
description: resolveLocalised(tool.summary, 'en'),
|
||||
applicationCategory: 'MultimediaApplication',
|
||||
operatingSystem: 'Any',
|
||||
offers: {
|
||||
'@type': 'Offer',
|
||||
price: '0',
|
||||
priceCurrency: 'USD',
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
|
||||
/>
|
||||
{template.sections.map((section: any) => (
|
||||
<SectionRenderer key={section.id} section={section} context={context} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Metadata } from 'next';
|
||||
import { getPageConfig, getAllTools, getAllApps, getAllCategories } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'All AI Photo Tools | Free Online Directory',
|
||||
description: 'Browse all free online AI photo editing tools: blemish remover, background cutout, photo enhancer, old photo restorer, and anime avatars.',
|
||||
};
|
||||
|
||||
export default function ToolsIndexPage() {
|
||||
const page = getPageConfig('tools');
|
||||
if (!page) notFound();
|
||||
|
||||
const tools = getAllTools();
|
||||
const apps = getAllApps();
|
||||
const categories = getAllCategories();
|
||||
|
||||
const context = {
|
||||
page,
|
||||
tools,
|
||||
apps,
|
||||
categories,
|
||||
locale: 'en',
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={context} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Metadata } from 'next';
|
||||
import { getPageConfig } from '@/lib/config/loader';
|
||||
import { SectionRenderer } from '@/components/sections/SectionRenderer';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Trust & Biometric Privacy Safeguards | Ekagni PhotoAI',
|
||||
description: 'Our four privacy pillars: Zero-storage, RAM processing, no model training on user photos, and strict biometric protections.',
|
||||
};
|
||||
|
||||
export default function TrustPage() {
|
||||
const page = getPageConfig('trust');
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
<div>
|
||||
{page.sections.map((section) => (
|
||||
<SectionRenderer key={section.id} section={section} context={{ page, locale: 'en' }} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user