"use strict";(()=>{var e={};e.id=447,e.ids=[447],e.modules={3524:e=>{e.exports=require("@prisma/client")},7096:e=>{e.exports=require("bcrypt")},9344:e=>{e.exports=require("jsonwebtoken")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},6705:e=>{e.exports=import("formidable")},7147:e=>{e.exports=require("fs")},1017:e=>{e.exports=require("path")},9596:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.r(t),r.d(t,{config:()=>p,default:()=>u,routeModule:()=>d});var s=r(1802),i=r(7153),o=r(6249),l=r(120),n=e([l]);l=(n.then?(await n)():n)[0];let u=(0,o.l)(l,"default"),p=(0,o.l)(l,"config"),d=new s.PagesAPIRouteModule({definition:{kind:i.x.PAGES_API,page:"/api/v1/materials/upload-zip",pathname:"/api/v1/materials/upload-zip",bundlePath:"",filename:""},userland:l});a()}catch(e){a(e)}})},9036:(e,t,r)=>{r.d(t,{A:()=>i,I:()=>s});let a={uploadMaxMB:3},s=()=>a,i=e=>("number"==typeof e.uploadMaxMB&&(a.uploadMaxMB=e.uploadMaxMB),a)},120:(e,t,r)=>{r.a(e,async(e,a)=>{try{r.r(t),r.d(t,{config:()=>m,default:()=>f});var s=r(8103),i=r(9036),o=r(432),l=r(6705),n=r(7147),u=r.n(n),p=r(1017),d=r.n(p),c=e([l]);l=(c.then?(await c)():c)[0];let m={api:{bodyParser:!1}};async function f(e,t){if("POST"!==e.method)return t.status(405).json({success:!1,error:"Method not allowed"});if(!await (0,s.m)(e,t))return;let{uploadMaxMB:r}=(0,i.I)(),a=1048576*r,n=(0,l.default)({maxFileSize:a,multiples:!1,filter:({mimetype:e,originalFilename:t})=>"application/zip"===e||(t||"").toLowerCase().endsWith(".zip")});try{let{fields:s,files:i}=await new Promise((t,r)=>{n.parse(e,(e,a,s)=>{e?r(e):t({fields:a,files:s})})}),l=(e=>{if(!e)return null;let t=Object.values(e||{});if(!t.length)return null;let r=t[0];return Array.isArray(r)?r[0]||null:r||null})(i);if(!l)return t.status(400).json({success:!1,error:"No file provided"});if((l.size||0)>a)return t.status(413).json({success:!1,error:`File too large. Max ${r}MB`});let p=d().join(process.cwd(),"public","uploads");u().existsSync(p)||u().mkdirSync(p,{recursive:!0});let c=`zip_${Date.now()}_${d().basename(l.originalFilename||"asset.zip")}`,f=d().join(p,c),m=l.filepath||l.path;if(!m)return t.status(400).json({success:!1,error:"Invalid upload temp path"});await u().promises.copyFile(m,f);let x=`/uploads/${c}`,g=await o.U.createMaterial(e.user.id,{title:s?.title?.toString()||"ZIP Asset",description:s?.description?.toString()||"Uploaded ZIP asset",type:"ASSET_ZIP",contentUrl:x,tags:(s?.tags?.toString()||"").split(",").filter(Boolean)});return t.status(201).json({success:!0,data:g})}catch(e){return console.error("Upload ZIP error:",e),t.status(500).json({success:!1,error:e.message||"Upload failed"})}}a()}catch(e){a(e)}})}};var t=require("../../../../webpack-api-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[876],()=>r(9596));module.exports=a})();