"use strict";exports.id=7558,exports.ids=[7558,1308],exports.modules={47558:(e,t,a)=>{a.r(t),a.d(t,{fulfillPteroOrder:()=>n});var r=a(72331),s=a(41308),i=a(76876);async function n(e){let t=await r.default.pterodactylServer.findUnique({where:{id:e},include:{user:!0,package:!0}});if(!t)throw Error("Server record not found");if("PENDING"!==t.status)return;let a=t.pteroUserId,n=t.pteroUsername,o=t.pteroPassword;try{if(!a){let e=await (0,s.getPteroUserByEmail)(t.user.email);if(e)a=e.id,n=n||e.username;else{o||(o=Math.random().toString(36).slice(-10)+Math.random().toString(36).slice(-4).toUpperCase());let e=(n||t.user.name.replace(/[^a-zA-Z0-9._-]/g,"").toLowerCase()||`user_${t.userId.slice(-6)}`).slice(0,32),r=await (0,s.createPteroUser)(t.user.email,e,t.user.name,"AmaneNime",o);a=r.id,n=r.username}}let l=`${t.package.name} - ${t.user.name}`,d=await (0,s.createPteroServer)({name:l.slice(0,50),userId:a,eggId:t.package.eggId,nestId:t.package.nestId,locationId:t.package.locationId,memory:t.package.memory,disk:t.package.disk,cpu:t.package.cpu,databases:t.package.databases,backups:t.package.backups,allocations:t.package.allocations,image:t.package.image,startup:t.package.startup||void 0}),c=new Date;c.setDate(c.getDate()+t.package.durationDays),await r.default.pterodactylServer.update({where:{id:e},data:{pteroUserId:a,pteroUsername:n,pteroPassword:o||null,pteroServerId:d.id,pteroIdentifier:d.identifier,status:"ACTIVE",expiresAt:c,lastRenewedAt:new Date}});let u=process.env.PTERODACTYL_URL||"https://panel.example.com";return await (0,i._b)(t.user,{name:t.user.name,orderId:t.id,productName:`Hosting: ${t.package.name}`,email:n||t.user.email,password:o||"(Sudah pernah dibuat, gunakan password panel Anda)",extra:`Panel URL: ${u}
Server Identifier: ${d.identifier}`}),{success:!0,identifier:d.identifier}}catch(e){throw console.error("[PTERO FULFILLMENT ERROR]",e),e}}},41308:(e,t,a)=>{a.r(t),a.d(t,{createPteroServer:()=>l,createPteroUser:()=>o,deletePteroServer:()=>u,getPteroUserByEmail:()=>n,suspendPteroServer:()=>d,unsuspendPteroServer:()=>c});let r=process.env.PTERODACTYL_URL||"https://panel.example.com",s=process.env.PTERODACTYL_ADMIN_KEY||"";async function i(e,t={}){let a=`${r}/api/application${e}`,i={Authorization:`Bearer ${s}`,Accept:"application/json","Content-Type":"application/json",...t.headers||{}},n=await fetch(a,{...t,headers:i});if(!n.ok){let e=n.statusText;try{let t=await n.json();t.errors&&t.errors.length>0&&(e=t.errors.map(e=>e.detail||e.code).join(", "))}catch(e){}throw Error(`Pterodactyl API Error (${n.status}): ${e}`)}return 204===n.status?null:n.json()}async function n(e){let t=await i(`/users?filter[email]=${encodeURIComponent(e)}`);return t&&t.data&&t.data.length>0?t.data[0].attributes:null}async function o(e,t,a,r,s){let n=await i(`/users?filter[username]=${encodeURIComponent(t)}`),o=t;n&&n.data&&n.data.length>0&&(o=`${t}_${Math.floor(1e4*Math.random())}`);let l={email:e,username:o,first_name:a,last_name:r||"User"};return s&&(l.password=s),(await i("/users",{method:"POST",body:JSON.stringify(l)})).attributes}async function l(e){let t={},a="";try{let r=await i(`/nests/${e.nestId}/eggs/${e.eggId}?include=variables`);if(r&&r.attributes&&(a=r.attributes.startup||"",r.attributes.relationships&&r.attributes.relationships.variables))for(let e of r.attributes.relationships.variables.data){let a=e.attributes.env_variable,r=e.attributes.default_value;t[a]=null!==r?String(r):""}}catch(e){console.warn("[PTERO] Failed to fetch egg variables, using fallbacks",e)}("SERVER_MEMORY"in t||!Object.keys(t).length)&&(t.SERVER_MEMORY=e.memory.toString()),("SERVER_IP"in t||!Object.keys(t).length)&&(t.SERVER_IP="0.0.0.0"),("SERVER_PORT"in t||!Object.keys(t).length)&&(t.SERVER_PORT="25565");let r={name:e.name,user:e.userId,egg:e.eggId,docker_image:e.image,startup:e.startup||a||" ",environment:t,limits:{memory:e.memory,swap:0,disk:e.disk,io:500,cpu:e.cpu},feature_limits:{databases:e.databases,backups:e.backups,allocations:e.allocations},deploy:{locations:[e.locationId],dedicated_ip:!1,port_range:[]}};return(await i("/servers",{method:"POST",body:JSON.stringify(r)})).attributes}async function d(e){await i(`/servers/${e}/suspend`,{method:"POST"})}async function c(e){await i(`/servers/${e}/unsuspend`,{method:"POST"})}async function u(e){await i(`/servers/${e}`,{method:"DELETE"})}}};