import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  experimental: {
    serverActions: { bodySizeLimit: "10mb" },
  },
  outputFileTracingIncludes: {
    "/api/**": [
      "../wiki/**",
      "../processing/**",
      "../raw/*--subagent/**",
      "../raw/_batch-rebuild/**",
    ],
    "/d/**": ["../wiki/**", "../raw/*--subagent/**"],
    "/admin/**": ["../raw/_batch-rebuild/**"],
  },
  // Built-in image optimization: Next.js fetches the source PNG from our
  // /api/static route, then serves resized + cached + AVIF/WebP versions
  // on demand. This keeps thumbnail-grid pages from hammering 200+ MB of PNGs.
  images: {
    remotePatterns: [
      { protocol: "https", hostname: "app.disclosure.top" },
      { protocol: "https", hostname: "disclosure.top" },
      { protocol: "http",  hostname: "localhost" },
    ],
    formats: ["image/avif", "image/webp"],
    minimumCacheTTL: 60 * 60 * 24 * 30,  // 30 days
  },
  async redirects() {
    return [
      { source: "/d/:docId/v2", destination: "/d/:docId", permanent: true },
      { source: "/d/:docId/v2/:pageId", destination: "/d/:docId/:pageId", permanent: true },
      { source: "/d/:docId/full", destination: "/d/:docId", permanent: true },
    ];
  },
};

export default nextConfig;
