module.exports=[93695,(e,t,r)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},70406,(e,t,r)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},18622,(e,t,r)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},24725,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},85873,e=>{"use strict";var t=e.i(47909),r=e.i(74017),a=e.i(96250),s=e.i(59756),n=e.i(61916),o=e.i(14444),i=e.i(37092),d=e.i(69741),l=e.i(16795),c=e.i(87718),u=e.i(95169),p=e.i(47587),h=e.i(66012),f=e.i(70101),m=e.i(26937),g=e.i(10372),x=e.i(93695);e.i(52474);var R=e.i(5232),v=e.i(89171),w=e.i(89660);async function _(e,{params:t}){try{let e,r,{id:a}=await t,s=await (0,w.createClient)(),{data:{user:n}}=await s.auth.getUser(),{data:o,error:i}=await w.supabaseAdmin.from("feeds").select(`
                *,
                character:characters (
                    id,
                    name,
                    image_url,
                    visibility,
                    user_id
                )
            `).eq("id",a).maybeSingle();if(i)return console.error("Error fetching feed:",i),v.NextResponse.json({success:!1,error:"Failed to fetch feed"},{status:500});if(!o)return v.NextResponse.json({success:!1,error:"Feed not found"},{status:404});if(o.character?.visibility==="private"&&o.character.user_id!==n?.id)return v.NextResponse.json({success:!1,error:"Forbidden"},{status:403});let{data:d,error:l}=await s.from("feed_comments").select(`
                id,
                content,
                created_at,
                user_id,
                parent_id,
                profile:profiles (
                    id,
                    name,
                    avatar_url
                ),
                is_ai_generated
            `).eq("feed_id",a).order("created_at",{ascending:!0});l&&console.error("Error fetching comments:",l);let c=new Date(o.created_at),u=c.toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"}),p=c.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0}),h=!1;if(n){let{data:e}=await s.from("post_likes").select("id").eq("post_id",a).eq("user_id",n.id).maybeSingle();h=!!e}return v.NextResponse.json({success:!0,feed:{id:o.id,characterId:o.character_id,characterName:(Array.isArray(o.character)?o.character[0]?.name:o.character?.name)||"Unknown",characterAvatar:(Array.isArray(o.character)?o.character[0]?.image_url:o.character?.image_url)||"",type:o.type,content:o.content,mediaUrl:o.media_url,likes:o.likes_count,isLiked:h,comments_count:o.comments_count,date:u,time:p,metadata:o.metadata||{},userId:o.user_id,characterVisibility:Array.isArray(o.character)?o.character[0]?.visibility:o.character?.visibility,characterUserId:Array.isArray(o.character)?o.character[0]?.user_id:o.character?.user_id,comments:(e=new Map,r=[],(d||[]).forEach(t=>{let r={id:t.id,content:t.content,createdAt:t.created_at,userName:t.profile?.name||"Anonymous",userAvatar:t.profile?.avatar_url||"",parentId:t.parent_id,isAiGenerated:t.is_ai_generated,userId:t.user_id,replies:[]};e.set(t.id,r)}),e.forEach(t=>{if(t.parentId){let a=e.get(t.parentId);a?a.replies.push(t):r.push(t)}else r.push(t)}),r)}})}catch(e){return console.error("Critical Feed Detail API Failure:",e),v.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}async function y(e,{params:t}){console.log("DELETE request received");try{let{id:e}=await t;console.log("Deleting feed with ID:",e);let r=await (0,w.createClient)(),{data:{user:a}}=await r.auth.getUser();if(!a)return console.log("Unauthorized delete attempt"),v.NextResponse.json({success:!1,error:"Unauthorized"},{status:401});console.log("User identified:",a.id);let{data:s,error:n}=await w.supabaseAdmin.from("feeds").select(`
                user_id,
                character:characters (
                    user_id
                )
            `).eq("id",e).maybeSingle();if(n)return console.error("❌ Error fetching post for deletion:",JSON.stringify(n,null,2)),v.NextResponse.json({success:!1,error:"Failed to verify ownership",details:n},{status:500});if(!s)return console.log("❌ Feed not found for deletion in DB. Searched ID:",e),v.NextResponse.json({success:!1,error:"Post not found",debugId:e},{status:404});let o=s.user_id===a.id,i=s.character?.user_id===a.id;if(console.log("Ownership check:",{isPostOwner:o,isCharacterOwner:i,feedUserId:s.user_id,charUserId:s.character?.user_id,userId:a.id}),!o&&!i)return console.log("Forbidden delete attempt: User does not own the post or the character"),v.NextResponse.json({success:!1,error:"Forbidden: You do not own this post"},{status:403});console.log("Deleting associated comments...");let{error:d}=await w.supabaseAdmin.from("feed_comments").delete().eq("feed_id",e);d&&console.warn("Non-fatal error deleting comments:",d),console.log("Deleting feed item...");let{error:l}=await w.supabaseAdmin.from("feeds").delete().eq("id",e);if(l)return console.error("❌ Error deleting post record:",l),v.NextResponse.json({success:!1,error:"Failed to delete post",details:l},{status:500});return console.log("Post deleted successfully"),v.NextResponse.json({success:!0,message:"Post deleted successfully"})}catch(e){return console.error("Critical Post Deletion API Failure:",e),v.NextResponse.json({success:!1,error:"Internal server error",details:e?.message||String(e)},{status:500})}}async function E(e,{params:t}){try{let{id:r}=await t,{content:a,parentId:s}=await e.json(),n=await (0,w.createClient)(),{data:{user:o}}=await n.auth.getUser();if(!o)return v.NextResponse.json({success:!1,error:"Unauthorized"},{status:401});if(!a||!a.trim())return v.NextResponse.json({success:!1,error:"Content is required"},{status:400});let{data:i,error:d}=await w.supabaseAdmin.from("feeds").select("user_id, character_id").eq("id",r).single();if(d||!i)return v.NextResponse.json({success:!1,error:"Feed not found"},{status:404});let{data:l,error:c}=await n.from("feed_comments").insert({feed_id:r,user_id:o.id,content:a.trim(),parent_id:s||null}).select().single();if(c)return console.error("Error inserting comment:",c),v.NextResponse.json({success:!1,error:"Failed to post comment"},{status:500});return v.NextResponse.json({success:!0,comment:l})}catch(e){return console.error("Comment Post Error:",e),v.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}e.s(["DELETE",()=>y,"GET",()=>_,"POST",()=>E],48750);var A=e.i(48750);let N=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/feeds/[id]/route",pathname:"/api/feeds/[id]",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/app/api/feeds/[id]/route.ts",nextConfigOutput:"standalone",userland:A}),{workAsyncStorage:b,workUnitAsyncStorage:C,serverHooks:j}=N;function I(){return(0,a.patchFetch)({workAsyncStorage:b,workUnitAsyncStorage:C})}async function P(e,t,a){N.isDev&&(0,s.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let v="/api/feeds/[id]/route";v=v.replace(/\/index$/,"")||"/";let w=await N.prepare(e,t,{srcPage:v,multiZoneDraftMode:!1});if(!w)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:_,params:y,nextConfig:E,parsedUrl:A,isDraftMode:b,prerenderManifest:C,routerServerContext:j,isOnDemandRevalidate:I,revalidateOnlyGenerated:P,resolvedPathname:q,clientReferenceManifest:S,serverActionsManifest:U}=w,T=(0,d.normalizeAppPath)(v),k=!!(C.dynamicRoutes[T]||C.routes[q]),D=async()=>((null==j?void 0:j.render404)?await j.render404(e,t,A,!1):t.end("This page could not be found"),null);if(k&&!b){let e=!!C.routes[q],t=C.dynamicRoutes[T];if(t&&!1===t.fallback&&!e){if(E.experimental.adapterPath)return await D();throw new x.NoFallbackError}}let O=null;!k||N.isDev||b||(O="/index"===(O=q)?"/":O);let F=!0===N.isDev||!k,H=k&&!F;U&&S&&(0,o.setReferenceManifestsSingleton)({page:v,clientReferenceManifest:S,serverActionsManifest:U,serverModuleMap:(0,i.createServerModuleMap)({serverActionsManifest:U})});let M=e.method||"GET",L=(0,n.getTracer)(),$=L.getActiveScopeSpan(),K={params:y,prerenderManifest:C,renderOpts:{experimental:{authInterrupts:!!E.experimental.authInterrupts},cacheComponents:!!E.cacheComponents,supportsDynamicResponse:F,incrementalCache:(0,s.getRequestMeta)(e,"incrementalCache"),cacheLifeProfiles:E.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a)=>N.onRequestError(e,t,a,j)},sharedContext:{buildId:_}},B=new l.NodeNextRequest(e),G=new l.NodeNextResponse(t),z=c.NextRequestAdapter.fromNodeNextRequest(B,(0,c.signalFromNodeResponse)(t));try{let o=async e=>N.handle(z,K).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=L.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${M} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t)}else e.updateName(`${M} ${v}`)}),i=!!(0,s.getRequestMeta)(e,"minimalMode"),d=async s=>{var n,d;let l=async({previousCacheEntry:r})=>{try{if(!i&&I&&P&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let n=await o(s);e.fetchMetrics=K.renderOpts.fetchMetrics;let d=K.renderOpts.pendingWaitUntil;d&&a.waitUntil&&(a.waitUntil(d),d=void 0);let l=K.renderOpts.collectedTags;if(!k)return await (0,h.sendResponse)(B,G,n,K.renderOpts.pendingWaitUntil),null;{let e=await n.blob(),t=(0,f.toNodeOutgoingHttpHeaders)(n.headers);l&&(t[g.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==K.renderOpts.collectedRevalidate&&!(K.renderOpts.collectedRevalidate>=g.INFINITE_CACHE)&&K.renderOpts.collectedRevalidate,a=void 0===K.renderOpts.collectedExpire||K.renderOpts.collectedExpire>=g.INFINITE_CACHE?void 0:K.renderOpts.collectedExpire;return{value:{kind:R.CachedRouteKind.APP_ROUTE,status:n.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await N.onRequestError(e,t,{routerKind:"App Router",routePath:v,routeType:"route",revalidateReason:(0,p.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:I})},j),t}},c=await N.handleResponse({req:e,nextConfig:E,cacheKey:O,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:C,isRoutePPREnabled:!1,isOnDemandRevalidate:I,revalidateOnlyGenerated:P,responseGenerator:l,waitUntil:a.waitUntil,isMinimalMode:i});if(!k)return null;if((null==c||null==(n=c.value)?void 0:n.kind)!==R.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==c||null==(d=c.value)?void 0:d.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});i||t.setHeader("x-nextjs-cache",I?"REVALIDATED":c.isMiss?"MISS":c.isStale?"STALE":"HIT"),b&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let u=(0,f.fromNodeOutgoingHttpHeaders)(c.value.headers);return i&&k||u.delete(g.NEXT_CACHE_TAGS_HEADER),!c.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,m.getCacheControlHeader)(c.cacheControl)),await (0,h.sendResponse)(B,G,new Response(c.value.body,{headers:u,status:c.value.status||200})),null};$?await d($):await L.withPropagatedContext(e.headers,()=>L.trace(u.BaseServerSpan.handleRequest,{spanName:`${M} ${v}`,kind:n.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},d))}catch(t){if(t instanceof x.NoFallbackError||await N.onRequestError(e,t,{routerKind:"App Router",routePath:T,routeType:"route",revalidateReason:(0,p.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:I})}),k)throw t;return await (0,h.sendResponse)(B,G,new Response(null,{status:500})),null}}e.s(["handler",()=>P,"patchFetch",()=>I,"routeModule",()=>N,"serverHooks",()=>j,"workAsyncStorage",()=>b,"workUnitAsyncStorage",()=>C],85873)}];

//# sourceMappingURL=%5Broot-of-the-server%5D__55656f33._.js.map