import { r as SanitizedNextlyConfig } from '../_dts-chunks/auth-service.d-B0csjDLa.d.ts'; import '@nextlyhq/adapter-drizzle'; import '@nextlyhq/adapter-drizzle/types'; import 'react'; import '../_dts-chunks/nextly-error.d-WlStqaV9.d.ts'; import '../_dts-chunks/error-codes.d-CbwkO1ux.d.ts'; import '../_dts-chunks/media.d-DtIw8UQM.d.ts'; import 'zod'; import '../_dts-chunks/storage.d-CEowrt6p.d.ts'; import 'drizzle-orm'; /** * Dynamic Media Route Handler * * Creates HTTP method handlers for Next.js media API routes using a catch-all pattern. * This provides a single handler that routes all media operations (files, folders). * * Uses a single catch-all route to handle all media-related endpoints, * simplifying the consumer's route structure. * * **IMPORTANT:** For storage plugins (S3, Vercel Blob, etc.) to work, you must * initialize Nextly with your config before these routes are called. The recommended * approach is to use Next.js instrumentation: * * ```typescript * // src/instrumentation.ts * export async function register() { * if (process.env.NEXT_RUNTIME === "nodejs") { * const { getNextly } = await import("nextly"); * const nextlyConfig = (await import("./nextly.config")).default; * await getNextly({ config: nextlyConfig }); * } * } * ``` * * @example * ```typescript * // In your Next.js app: app/api/media/[[...path]]/route.ts * import { createMediaHandlers } from 'nextly/api/media-handlers'; * * const handlers = createMediaHandlers(); * export const GET = handlers.GET; * export const POST = handlers.POST; * export const PATCH = handlers.PATCH; * export const DELETE = handlers.DELETE; * ``` * * Supported Routes: * - GET /api/media - List media with pagination * - POST /api/media - Upload new media file * - GET /api/media/:id - Get media by ID * - PATCH /api/media/:id - Update media metadata * - DELETE /api/media/:id - Delete media file * - PATCH /api/media/:id/move - Move media to folder * - GET /api/media/folders - List folders * - POST /api/media/folders - Create folder * - GET /api/media/folders/:id - Get folder by ID * - PATCH /api/media/folders/:id - Update folder * - DELETE /api/media/folders/:id - Delete folder * - GET /api/media/folders/:id/contents - Get folder contents * - GET /api/media/folders/root/contents - Get root folder contents * * @module api/media-handlers */ /** * Route context for Next.js App Router dynamic routes. */ interface RouteContext { params: Promise<{ path?: string[]; }>; } /** * Options for creating media handlers. */ interface MediaHandlerOptions { /** * Nextly configuration object. * Pass this to ensure storage plugins are available even if * instrumentation hasn't run in this worker process. */ config?: SanitizedNextlyConfig; /** * Gate every operation behind a media permission and take the acting * identity from the authenticated session/API key rather than the request * body. Use this for the admin-facing mount (`/admin/api/media`), where the * `Path=/admin` session cookie can reach. The public mount omits it and * serves reads only. Off by default so existing public mounts are unchanged * in shape (their write verbs stop serving — see below). */ requireAuth?: boolean; } /** * Create dynamic HTTP method handlers for Next.js media API routes * * Use with a catch-all route pattern: app/api/media/[[...path]]/route.ts * * @param options - Optional configuration including nextly config * @returns Object with handlers for GET, POST, PATCH, DELETE */ declare function createMediaHandlers(options?: MediaHandlerOptions): { GET: (request: Request, ctx: RouteContext) => Promise; POST: (request: Request, ctx: RouteContext) => Promise; PATCH: (request: Request, ctx: RouteContext) => Promise; DELETE: (request: Request, ctx: RouteContext) => Promise; }; export { createMediaHandlers }; export type { MediaHandlerOptions, RouteContext };