"use strict";(()=>{var e={};e.id=5998,e.ids=[5998],e.modules={2934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},4580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},5869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},4277:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>x,requestAsyncStorage:()=>g,routeModule:()=>d,serverHooks:()=>h,staticGenerationAsyncStorage:()=>m});var a={};r.r(a),r.d(a,{POST:()=>c});var s=r(9303),o=r(8716),n=r(670),i=r(7070),p=r(5655),u=r(987);let l={"reference-images":"private","product-images":"private",avatars:"public"};async function c(e){if(!(0,u._)(e))return i.NextResponse.json((0,u.E)(),{status:403});let t=(0,p.e)(),{data:{user:r}}=await t.auth.getUser();if(!r)return i.NextResponse.json({error:"Unauthorized"},{status:401});let a=await e.formData(),s=a.get("file"),o=a.get("bucket")??"reference-images";if(!s)return i.NextResponse.json({error:"No file provided"},{status:400});if(!Object.keys(l).includes(o))return i.NextResponse.json({error:"Invalid bucket"},{status:400});if(s.size>10485760)return i.NextResponse.json({error:"File too large (max 10MB)"},{status:400});if(!["image/jpeg","image/png","image/webp","image/gif"].includes(s.type))return i.NextResponse.json({error:"Invalid file type. Allowed: JPEG, PNG, WebP, GIF"},{status:400});let n={"image/jpeg":"jpg","image/png":"png","image/webp":"webp","image/gif":"gif"}[s.type],c=`${r.id}/${Date.now()}.${n}`,{data:d,error:g}=await t.storage.from(o).upload(c,s,{contentType:s.type,upsert:!1});if(g)return i.NextResponse.json({error:g.message},{status:500});if("private"===l[o]){let{data:e,error:r}=await t.storage.from(o).createSignedUrl(d.path,3600);return r||!e?i.NextResponse.json({path:d.path,bucket:o,url:null}):i.NextResponse.json({url:e.signedUrl,path:d.path,bucket:o})}let{data:{publicUrl:m}}=t.storage.from(o).getPublicUrl(d.path);return i.NextResponse.json({url:m,path:d.path,bucket:o})}let d=new s.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/upload/route",pathname:"/api/upload",filename:"route",bundlePath:"app/api/upload/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/upload/route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:g,staticGenerationAsyncStorage:m,serverHooks:h}=d,f="/api/upload/route";function x(){return(0,n.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:m})}},987:(e,t,r)=>{function a(e){let t=e.headers.get("origin");if(!t)return!0;let r="http://localhost:3000";if(new Set([r,"http://localhost:3000","http://localhost:3001","http://127.0.0.1:3000"].filter(Boolean)).has(t))return!0;try{let e=new URL(t).hostname,a=r?new URL(r).hostname:"";if(a&&(e===a||e.endsWith(`.${a}`)))return!0}catch{}return!1}function s(){return{success:!1,error:"Forbidden: invalid request origin"}}r.d(t,{E:()=>s,_:()=>a})},5655:(e,t,r)=>{r.d(t,{e:()=>o});var a=r(5238),s=r(1615);function o(){let e=(0,s.cookies)();return(0,a.l)("https://dummy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.dummy",{cookies:{getAll:()=>e.getAll(),setAll(t){try{t.forEach(({name:t,value:r,options:a})=>e.set(t,r,a))}catch{}}}})}}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[9276,6164,5972],()=>r(4277));module.exports=a})();