"use strict";(()=>{var e={};e.id=766,e.ids=[766],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")},7610:(e,r,t)=>{t.a(e,async(e,s)=>{try{t.r(r),t.d(r,{config:()=>d,default:()=>u,routeModule:()=>p});var a=t(1802),i=t(7153),o=t(6249),n=t(3250),l=e([n]);n=(l.then?(await l)():l)[0];let u=(0,o.l)(n,"default"),d=(0,o.l)(n,"config"),p=new a.PagesAPIRouteModule({definition:{kind:i.x.PAGES_API,page:"/api/v1/materials/upload-video",pathname:"/api/v1/materials/upload-video",bundlePath:"",filename:""},userland:n});s()}catch(e){s(e)}})},9036:(e,r,t)=>{t.d(r,{A:()=>i,I:()=>a});let s={uploadMaxMB:3},a=()=>s,i=e=>("number"==typeof e.uploadMaxMB&&(s.uploadMaxMB=e.uploadMaxMB),s)},3250:(e,r,t)=>{t.a(e,async(e,s)=>{try{t.r(r),t.d(r,{config:()=>M,default:()=>m});var a=t(8103),i=t(9036),o=t(7556),n=t(432),l=t(6705),u=t(7147),d=t.n(u),p=t(1017),c=t.n(p),f=e([l]);l=(f.then?(await f)():f)[0];let M={api:{bodyParser:!1}};async function m(e,r){if("POST"!==e.method)return r.status(405).json({success:!1,error:"Method not allowed"});if(!await (0,a.m)(e,r))return;if(e.user.role!==o.i.MANAGER&&e.user.role!==o.i.ADMIN)return r.status(403).json({success:!1,error:"Manager role required"});let{uploadMaxMB:t}=(0,i.I)(),s=1048576*t,u=(0,l.default)({maxFileSize:s,multiples:!1,filter:({mimetype:e,originalFilename:r})=>{let t=(r||"").toLowerCase();return e?.startsWith("video/")||t.endsWith(".mp4")||t.endsWith(".webm")||t.endsWith(".mov")}});try{let{fields:a,files:i}=await new Promise((r,t)=>{u.parse(e,(e,s,a)=>{e?t(e):r({fields:s,files:a})})}),o=(e=>{if(!e)return null;let r=Object.values(e||{});if(!r.length)return null;let t=r[0];return Array.isArray(t)?t[0]||null:t||null})(i);if(!o)return r.status(400).json({success:!1,error:"No file provided"});if((o.size||0)>s)return r.status(413).json({success:!1,error:`File too large. Max ${t}MB`});let l=c().join(process.cwd(),"public","uploads");d().existsSync(l)||d().mkdirSync(l,{recursive:!0});let p=`video_${Date.now()}_${c().basename(o.originalFilename||"video.mp4")}`,f=c().join(l,p),m=o.filepath||o.path;if(!m)return r.status(400).json({success:!1,error:"Invalid upload temp path"});await d().promises.copyFile(m,f);let M=`/uploads/${p}`,v=await n.U.createMaterial(e.user.id,{title:a?.title?.toString()||"Video Asset",description:a?.description?.toString()||"Uploaded video asset",type:"VIDEO",contentUrl:M,tags:(a?.tags?.toString()||"").split(",").filter(Boolean)});return r.status(201).json({success:!0,data:v})}catch(e){return console.error("Upload VIDEO error:",e),r.status(500).json({success:!1,error:e.message||"Upload failed"})}}s()}catch(e){s(e)}})},7556:(e,r,t)=>{var s,a;t.d(r,{i:()=>s}),function(e){e.USER="USER",e.ADMIN="ADMIN",e.CREATOR="CREATOR",e.MANAGER="MANAGER"}(s||(s={})),function(e){e.CODE="CODE",e.ASSET_ZIP="ASSET_ZIP",e.VIDEO="VIDEO"}(a||(a={}))}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[876],()=>t(7610));module.exports=s})();