import { d as Media } from '../_dts-chunks/media.d-DtIw8UQM.d.ts'; import { O as OnErrorHook } from '../_dts-chunks/on-error.d-DGMUFaZB.d.ts'; import { P as PublicData } from '../_dts-chunks/nextly-error.d-WlStqaV9.d.ts'; import 'zod'; import '../_dts-chunks/error-codes.d-CbwkO1ux.d.ts'; /** * Media Upload Server Action * * Next.js 16 Server Action for uploading media files. * Provides a simpler alternative to API routes for small files (<5MB). * * ## Features * * - Server-side file upload (no client-side FormData serialization) * - Automatic cache revalidation (revalidatePath) * - Type-safe with Zod validation * - Authentication support (when configured) * - Error handling with user-friendly messages * * ## Usage * * ### In Consumer's Next.js App * * ```typescript * // app/actions/media.ts * 'use server'; * * import { uploadMediaAction } from 'nextly/actions/upload-media'; * import { getUserId } from './auth'; // Your auth implementation * * export async function uploadMedia(formData: FormData) { * const userId = await getUserId(); * return uploadMediaAction(formData, { uploadedBy: userId }); * } * ``` * * ### In Client Component * * ```tsx * 'use client'; * * import { uploadMedia } from './actions/media'; * * function UploadForm() { * async function handleSubmit(formData: FormData) { * const result = await uploadMedia(formData); * if (result.success) { * toast.success('Uploaded!'); * } else { * toast.error(result.error); * } * } * * return
; * } * ``` * * ## Authentication * * This action is **auth-agnostic** by design. The `uploadedBy` parameter * must be provided by the consumer's authentication implementation. * * Examples: * - Nextly: `const result = await getSession(request, secret); uploadedBy: result.user?.id` * - Clerk: `const { userId } = auth(); uploadedBy: userId` * - Custom: `const user = await getUser(); uploadedBy: user.id` * * ## Limitations * * - **No upload progress**: Server Actions don't support progress events * - **Recommended for small files only** (<5MB) * - **For large files**: Use API route with XMLHttpRequest * * @see packages/db/src/api/media.ts - API route with progress support * @see MEDIA-MANAGEMENT-EXTENDED-PLAN.md - Phase 6 implementation details */ /** * Server Action options */ interface UploadMediaActionOptions { /** * User ID who is uploading the file (required) * Must be obtained from your auth system */ uploadedBy: string; /** * Path to revalidate after successful upload * @default '/admin/media' */ revalidatePath?: string; } /** * Server Action result */ interface UploadMediaActionResult { success: boolean; data?: Media; error?: string; statusCode?: number; } /** * Upload media file via Server Action * * Uploads a file to storage and creates a database record. * Automatically generates thumbnails for images. * * @param formData - FormData containing the file * @param options - Upload options (uploadedBy, revalidatePath) * @returns Upload result with media data or error * * @example Basic usage * ```typescript * 'use server'; * * export async function uploadFile(formData: FormData) { * const userId = await getUserId(); // Your auth function * return uploadMediaAction(formData, { uploadedBy: userId }); * } * ``` * * @example With custom revalidation path * ```typescript * return uploadMediaAction(formData, { * uploadedBy: userId, * revalidatePath: '/dashboard/gallery', * }); * ``` */ declare function uploadMediaAction(formData: FormData, options: UploadMediaActionOptions): Promise