"use strict";(()=>{var e={};e.id=1780,e.ids=[1780],e.modules={30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},32081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},57147:e=>{e.exports=require("fs")},41808:e=>{e.exports=require("net")},71017:e=>{e.exports=require("path")},32739:(e,t,n)=>{n.r(t),n.d(t,{headerHooks:()=>E,originalPathname:()=>$,patchFetch:()=>A,requestAsyncStorage:()=>g,routeModule:()=>d,serverHooks:()=>m,staticGenerationAsyncStorage:()=>S,staticGenerationBailout:()=>h});var r={};n.r(r),n.d(r,{POST:()=>p});var s=n(95419),o=n(69108),i=n(99678),a=n(78070),u=n(34844),c=n(41808),l=n.n(c);async function p(e){if((0,u.Ts)())return a.Z.json({error:"Already installed"},{status:403});let t=await e.json();try{await new Promise((e,n)=>{let r=new(l()).Socket;r.setTimeout(5e3),r.on("connect",()=>{r.destroy(),e()}),r.on("timeout",()=>{r.destroy(),n(Error("Connection timeout"))}),r.on("error",e=>{n(e)}),r.connect(t.port,t.host)})}catch(e){return a.Z.json({success:!1,error:`Cannot reach ${t.host}:${t.port} — ${e.message}`})}let r=(0,u.r_)(t);try{let{execSync:e}=n(32081);return e(`npx prisma db execute --stdin --url "${r}"`,{input:"SELECT 1;",stdio:["pipe","pipe","pipe"],timeout:15e3,env:{...process.env,DATABASE_URL:r}}),a.Z.json({success:!0,message:"Connection successful"})}catch(n){let e=n.stderr?.toString()||n.message,t="Database connection failed";return e.includes("authentication")?t="Wrong username or password":e.includes("does not exist")||e.includes("Unknown database")?t="Database does not exist — please create it first":e.includes("ECONNREFUSED")&&(t="Connection refused — is the database server running?"),a.Z.json({success:!1,error:t})}}let d=new s.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/install/test-db/route",pathname:"/api/install/test-db",filename:"route",bundlePath:"app/api/install/test-db/route"},resolvedPagePath:"C:\\test2\\pagecraft-ai\\src\\app\\api\\install\\test-db\\route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:g,staticGenerationAsyncStorage:S,serverHooks:m,headerHooks:E,staticGenerationBailout:h}=d,$="/api/install/test-db/route";function A(){return(0,i.patchFetch)({serverHooks:m,staticGenerationAsyncStorage:S})}},34844:(e,t,n)=>{n.d(t,{Eg:()=>E,KK:()=>g,Ts:()=>d,gR:()=>h,r_:()=>S,yg:()=>m});var r=n(57147),s=n.n(r),o=n(71017),i=n.n(o),a=n(6113),u=n.n(a);let c=process.cwd(),l=i().join(c,"install.lock"),p=i().join(c,".env");function d(){return s().existsSync(l)}function g(){return u().randomBytes(32).toString("base64")}function S(e){let{type:t,host:n,port:r,database:s,username:o,password:i,ssl:a}=e,u=encodeURIComponent(i);return"postgresql"===t?`postgresql://${o}:${u}@${n}:${r}/${s}${a?"?sslmode=require":""}`:`mysql://${o}:${u}@${n}:${r}/${s}${a?"?ssl=true":""}`}function m(e){let t=`# Generated by PageCraft AI Installer
# ${new Date().toISOString()}

# Database
DATABASE_URL="${e.databaseUrl}"

# NextAuth
NEXTAUTH_SECRET="${e.nextAuthSecret}"
NEXTAUTH_URL="${e.nextAuthUrl}"

# Site URL (SEO, sitemap, OG tags)
NEXT_PUBLIC_SITE_URL="${e.siteUrl}"

# OpenRouter AI
OPENROUTER_API_KEY="${e.openRouterApiKey}"

# Unsplash (optional)
UNSPLASH_ACCESS_KEY="${e.unsplashAccessKey}"

# Google OAuth (optional)
GOOGLE_CLIENT_ID="${e.googleClientId}"
GOOGLE_CLIENT_SECRET="${e.googleClientSecret}"
`;s().writeFileSync(p,t,{encoding:"utf-8"})}function E(){let e=JSON.stringify({installedAt:new Date().toISOString(),version:"1.0.0"});s().writeFileSync(l,e,{encoding:"utf-8"})}function h(e){let t=i().join(c,`prisma/schema.${e}.prisma`),n=i().join(c,"prisma/schema.prisma");s().copyFileSync(t,n)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var n=e=>t(t.s=e),r=t.X(0,[1638,6206],()=>n(32739));module.exports=r})();