@minecraft-docker/mcctl-console 1.15.3 → 1.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.next/standalone/package.json +1 -1
  2. package/.next/standalone/platform/services/mcctl-console/.next/BUILD_ID +1 -1
  3. package/.next/standalone/platform/services/mcctl-console/.next/app-build-manifest.json +58 -58
  4. package/.next/standalone/platform/services/mcctl-console/.next/app-path-routes-manifest.json +1 -1
  5. package/.next/standalone/platform/services/mcctl-console/.next/build-manifest.json +2 -2
  6. package/.next/standalone/platform/services/mcctl-console/.next/prerender-manifest.json +1 -1
  7. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/audit-logs/page_client-reference-manifest.js +1 -1
  8. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/backups/page_client-reference-manifest.js +1 -1
  9. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/dashboard/page_client-reference-manifest.js +1 -1
  10. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/players/page_client-reference-manifest.js +1 -1
  11. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/routing/page_client-reference-manifest.js +1 -1
  12. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/servers/[name]/console/page_client-reference-manifest.js +1 -1
  13. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/servers/[name]/page_client-reference-manifest.js +1 -1
  14. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/servers/page_client-reference-manifest.js +1 -1
  15. package/.next/standalone/platform/services/mcctl-console/.next/server/app/(main)/worlds/page_client-reference-manifest.js +1 -1
  16. package/.next/standalone/platform/services/mcctl-console/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  17. package/.next/standalone/platform/services/mcctl-console/.next/server/app/_not-found.html +1 -1
  18. package/.next/standalone/platform/services/mcctl-console/.next/server/app/_not-found.rsc +1 -1
  19. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/audit-logs/[id]/route.js +1 -1
  20. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/audit-logs/export/route.js +1 -1
  21. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/audit-logs/route.js +2 -2
  22. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/audit-logs/stats/route.js +1 -1
  23. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/audit-logs/stream/route.js +2 -2
  24. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/auth/[...all]/route.js +1 -1
  25. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/backup/history/route.js +1 -1
  26. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/backup/restore/route.js +1 -1
  27. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/backup/route.js +1 -1
  28. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/players/ban/route.js +1 -1
  29. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/players/kick/route.js +1 -1
  30. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/players/op/route.js +1 -1
  31. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/players/route.js +1 -1
  32. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/players/whitelist/route.js +1 -1
  33. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/router/status/route.js +1 -1
  34. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/servers/[name]/[action]/route.js +1 -1
  35. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/servers/[name]/config/route.js +1 -1
  36. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/servers/[name]/exec/route.js +1 -1
  37. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/servers/[name]/route.js +1 -1
  38. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/servers/[name]/world/reset/route.js +1 -1
  39. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/servers/route.js +1 -1
  40. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/user-servers/[id]/route.js +2 -2
  41. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/user-servers/route.js +2 -2
  42. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/users/route.js +2 -2
  43. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/worlds/[name]/[action]/route.js +1 -1
  44. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/worlds/[name]/route.js +1 -1
  45. package/.next/standalone/platform/services/mcctl-console/.next/server/app/api/worlds/route.js +1 -1
  46. package/.next/standalone/platform/services/mcctl-console/.next/server/app/audit-logs.html +1 -1
  47. package/.next/standalone/platform/services/mcctl-console/.next/server/app/audit-logs.rsc +2 -2
  48. package/.next/standalone/platform/services/mcctl-console/.next/server/app/backups.html +1 -1
  49. package/.next/standalone/platform/services/mcctl-console/.next/server/app/backups.rsc +1 -1
  50. package/.next/standalone/platform/services/mcctl-console/.next/server/app/dashboard.html +1 -1
  51. package/.next/standalone/platform/services/mcctl-console/.next/server/app/dashboard.rsc +2 -2
  52. package/.next/standalone/platform/services/mcctl-console/.next/server/app/index.html +1 -1
  53. package/.next/standalone/platform/services/mcctl-console/.next/server/app/index.rsc +1 -1
  54. package/.next/standalone/platform/services/mcctl-console/.next/server/app/login/page_client-reference-manifest.js +1 -1
  55. package/.next/standalone/platform/services/mcctl-console/.next/server/app/login.html +1 -1
  56. package/.next/standalone/platform/services/mcctl-console/.next/server/app/login.rsc +1 -1
  57. package/.next/standalone/platform/services/mcctl-console/.next/server/app/page_client-reference-manifest.js +1 -1
  58. package/.next/standalone/platform/services/mcctl-console/.next/server/app/players.html +1 -1
  59. package/.next/standalone/platform/services/mcctl-console/.next/server/app/players.rsc +1 -1
  60. package/.next/standalone/platform/services/mcctl-console/.next/server/app/routing.html +1 -1
  61. package/.next/standalone/platform/services/mcctl-console/.next/server/app/routing.rsc +1 -1
  62. package/.next/standalone/platform/services/mcctl-console/.next/server/app/servers.html +1 -1
  63. package/.next/standalone/platform/services/mcctl-console/.next/server/app/servers.rsc +1 -1
  64. package/.next/standalone/platform/services/mcctl-console/.next/server/app/signup/page_client-reference-manifest.js +1 -1
  65. package/.next/standalone/platform/services/mcctl-console/.next/server/app/signup.html +1 -1
  66. package/.next/standalone/platform/services/mcctl-console/.next/server/app/signup.rsc +1 -1
  67. package/.next/standalone/platform/services/mcctl-console/.next/server/app/worlds.html +1 -1
  68. package/.next/standalone/platform/services/mcctl-console/.next/server/app/worlds.rsc +1 -1
  69. package/.next/standalone/platform/services/mcctl-console/.next/server/app-paths-manifest.json +18 -18
  70. package/.next/standalone/platform/services/mcctl-console/.next/server/chunks/613.js +1 -1
  71. package/.next/standalone/platform/services/mcctl-console/.next/server/middleware-manifest.json +5 -5
  72. package/.next/standalone/platform/services/mcctl-console/.next/server/next-font-manifest.js +1 -1
  73. package/.next/standalone/platform/services/mcctl-console/.next/server/next-font-manifest.json +1 -1
  74. package/.next/standalone/platform/services/mcctl-console/.next/server/pages/404.html +1 -1
  75. package/.next/standalone/platform/services/mcctl-console/.next/server/pages/500.html +1 -1
  76. package/.next/standalone/platform/services/mcctl-console/.next/server/pages-manifest.json +1 -1
  77. package/.next/standalone/platform/services/mcctl-console/.next/server/server-reference-manifest.json +1 -1
  78. package/.next/standalone/platform/services/mcctl-console/package.json +1 -1
  79. package/package.json +2 -2
  80. /package/.next/standalone/platform/services/mcctl-console/.next/static/{M6lBMs4O93dmAs487Ndg4 → ZVkcx2OmeAN6P00KKasi0}/_buildManifest.js +0 -0
  81. /package/.next/standalone/platform/services/mcctl-console/.next/static/{M6lBMs4O93dmAs487Ndg4 → ZVkcx2OmeAN6P00KKasi0}/_ssgManifest.js +0 -0
  82. /package/.next/standalone/platform/services/mcctl-console/.next/static/chunks/{2537-ad3cb492fdff51d8.js → 2537-6c9d2dfd403b7448.js} +0 -0
  83. /package/.next/standalone/platform/services/mcctl-console/.next/static/chunks/app/(main)/audit-logs/{page-6379e4fb97ec58d0.js → page-7a5d1441bb2811cf.js} +0 -0
  84. /package/.next/static/{M6lBMs4O93dmAs487Ndg4 → ZVkcx2OmeAN6P00KKasi0}/_buildManifest.js +0 -0
  85. /package/.next/static/{M6lBMs4O93dmAs487Ndg4 → ZVkcx2OmeAN6P00KKasi0}/_ssgManifest.js +0 -0
  86. /package/.next/static/chunks/{2537-ad3cb492fdff51d8.js → 2537-6c9d2dfd403b7448.js} +0 -0
  87. /package/.next/static/chunks/app/(main)/audit-logs/{page-6379e4fb97ec58d0.js → page-7a5d1441bb2811cf.js} +0 -0
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=3429,e.ids=[3429],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},87830:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>_,requestAsyncStorage:()=>f,routeModule:()=>E,serverHooks:()=>L,staticGenerationAsyncStorage:()=>N});var s={};r.r(s),r.d(s,{DELETE:()=>T,GET:()=>m,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";function p(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function m(e,{params:t}){try{let{name:e}=await t,r=await (0,u.Ke)(await (0,c.headers)(),e,"view"),s=(0,d.F0)(p(r)),a=await s.getServer(e);return i.NextResponse.json(a)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch server:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to fetch server details"},{status:500})}}async function T(e,{params:t}){try{let{name:r}=await t,s=await (0,u.Ke)(await (0,c.headers)(),r,"admin"),{searchParams:a}=new URL(e.url),n="true"===a.get("force"),o=(0,d.F0)(p(s)),l=await o.deleteServer(r,n);return i.NextResponse.json(l)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to delete server:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to delete server"},{status:500})}}let E=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/servers/[name]/route",pathname:"/api/servers/[name]",filename:"route",bundlePath:"app/api/servers/[name]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/servers/[name]/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:f,staticGenerationAsyncStorage:N,serverHooks:L}=E,h="/api/servers/[name]/route";function _(){return(0,o.patchFetch)({serverHooks:L,staticGenerationAsyncStorage:N})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>d});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=(0,s.kj)({database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
1
+ "use strict";(()=>{var e={};e.id=3429,e.ids=[3429],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},87830:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>f,routeModule:()=>E,serverHooks:()=>N,staticGenerationAsyncStorage:()=>h});var s={};r.r(s),r.d(s,{DELETE:()=>T,GET:()=>m,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";function p(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function m(e,{params:t}){try{let{name:e}=await t,r=await (0,u.Ke)(await (0,c.headers)(),e,"view"),s=(0,d.F0)(p(r)),a=await s.getServer(e);return i.NextResponse.json(a)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch server:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to fetch server details"},{status:500})}}async function T(e,{params:t}){try{let{name:r}=await t,s=await (0,u.Ke)(await (0,c.headers)(),r,"admin"),{searchParams:a}=new URL(e.url),n="true"===a.get("force"),o=(0,d.F0)(p(s)),l=await o.deleteServer(r,n);return i.NextResponse.json(l)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to delete server:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to delete server"},{status:500})}}let E=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/servers/[name]/route",pathname:"/api/servers/[name]",filename:"route",bundlePath:"app/api/servers/[name]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/servers/[name]/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:f,staticGenerationAsyncStorage:h,serverHooks:N}=E,L="/api/servers/[name]/route";function _(){return(0,o.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:h})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>c});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,s.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=5442,e.ids=[5442],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},25138:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>N,requestAsyncStorage:()=>T,routeModule:()=>m,serverHooks:()=>f,staticGenerationAsyncStorage:()=>E});var s={};r.r(s),r.d(s,{POST:()=>p,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";async function p(e,{params:t}){try{let{name:e}=await t,r=await (0,u.Ke)(await (0,c.headers)(),e,"admin"),s=(0,d.F0)({username:r.user.name||r.user.email,role:r.user.role||"user"}),a=await s.resetWorld(e);return i.NextResponse.json(a)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to reset world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to reset world"},{status:500})}}let m=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/servers/[name]/world/reset/route",pathname:"/api/servers/[name]/world/reset",filename:"route",bundlePath:"app/api/servers/[name]/world/reset/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/servers/[name]/world/reset/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:T,staticGenerationAsyncStorage:E,serverHooks:f}=m,L="/api/servers/[name]/world/reset/route";function N(){return(0,o.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:E})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>d});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=(0,s.kj)({database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
1
+ "use strict";(()=>{var e={};e.id=5442,e.ids=[5442],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},25138:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>L,requestAsyncStorage:()=>T,routeModule:()=>m,serverHooks:()=>f,staticGenerationAsyncStorage:()=>E});var s={};r.r(s),r.d(s,{POST:()=>p,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";async function p(e,{params:t}){try{let{name:e}=await t,r=await (0,u.Ke)(await (0,c.headers)(),e,"admin"),s=(0,d.F0)({username:r.user.name||r.user.email,role:r.user.role||"user"}),a=await s.resetWorld(e);return i.NextResponse.json(a)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to reset world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to reset world"},{status:500})}}let m=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/servers/[name]/world/reset/route",pathname:"/api/servers/[name]/world/reset",filename:"route",bundlePath:"app/api/servers/[name]/world/reset/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/servers/[name]/world/reset/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:T,staticGenerationAsyncStorage:E,serverHooks:f}=m,h="/api/servers/[name]/world/reset/route";function L(){return(0,o.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:E})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>c});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,s.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=6222,e.ids=[6222],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},4908:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>L,patchFetch:()=>S,requestAsyncStorage:()=>E,routeModule:()=>T,serverHooks:()=>N,staticGenerationAsyncStorage:()=>y});var t={};s.r(t),s.d(t,{GET:()=>h,POST:()=>v,dynamic:()=>m});var n=s(3025),a=s(45086),i=s(74048),o=s(24517),d=s(78649),u=s(60154),c=s(77605),l=s(97060),p=s(74888);let m="force-dynamic";function f(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function h(){try{let e=await (0,u.mk)(await (0,c.headers)()),r=(0,d.F0)(f(e)),s=await r.getServers();if("admin"===e.user.role)return o.NextResponse.json(s);let t=new l.x,n=await t.findByUser(e.user.id),a=new Set(n.map(e=>e.serverId)),i=s.servers.filter(e=>a.has(e.name));return o.NextResponse.json({servers:i,total:i.length})}catch(e){if(e instanceof u.l4)return o.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return o.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch servers:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to fetch servers"},{status:500})}}async function v(e){try{let r=await (0,u.mk)(await (0,c.headers)()),s=await e.json(),t=(0,d.F0)(f(r)),n=await t.createServer(s);if("admin"!==r.user.role){let e=new l.x,s=new p.e(e);try{await s.grantAccess(r.user.id,n.server.name,"admin")}catch(e){console.error("Failed to grant admin permission:",e)}}return o.NextResponse.json(n,{status:201})}catch(e){if(e instanceof u.l4)return o.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return o.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to create server:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to create server"},{status:500})}}let T=new n.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/servers/route",pathname:"/api/servers",filename:"route",bundlePath:"app/api/servers/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/servers/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:E,staticGenerationAsyncStorage:y,serverHooks:N}=T,L="/api/servers/route";function S(){return(0,i.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:y})}},78649:(e,r,s)=>{s.d(r,{F0:()=>a,zB:()=>t});class t extends Error{constructor(e,r,s){super(s),this.statusCode=e,this.error=r,this.name="McctlApiError"}}class n{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,r={}){let s=`${this.baseUrl}${e}`,n={"X-API-Key":this.apiKey};r.body&&(n["Content-Type"]="application/json"),this.userContext&&(n["X-User"]=this.userContext.username,n["X-Role"]=this.userContext.role);let a=await fetch(s,{...r,headers:{...n,...r.headers}});if(!a.ok){let e=await a.json().catch(()=>({error:"UnknownError",message:a.statusText}));throw new t(a.status,e.error,e.message)}return a.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,r){return this.fetch(`/api/servers/${encodeURIComponent(e)}${r?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,r){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:r})})}async getLogs(e,r=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${r}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,r){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:r})})}async releaseWorld(e,r){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${r?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,r){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${r?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,r){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(r)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let r=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:r})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function a(e){let r=process.env.MCCTL_API_URL||"http://localhost:5001",s=process.env.MCCTL_API_KEY||"";return s||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new n({baseUrl:r,apiKey:s,userContext:e})}},97060:(e,r,s)=>{s.d(r,{x:()=>i});var t=s(30579),n=s(22587),a=s(8290);class i{async findById(e){return(await n.db.select().from(a.userServers).where((0,t.eq)(a.userServers.id,e)).limit(1))[0]??null}async findByUserAndServer(e,r){return(await n.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r))).limit(1))[0]??null}async findByServer(e){return n.db.select().from(a.userServers).where((0,t.eq)(a.userServers.serverId,e))}async findByServerWithUsers(e){return(await n.db.select({id:a.userServers.id,userId:a.userServers.userId,serverId:a.userServers.serverId,permission:a.userServers.permission,createdAt:a.userServers.createdAt,updatedAt:a.userServers.updatedAt,user:{id:a.users.id,name:a.users.name,email:a.users.email,image:a.users.image}}).from(a.userServers).leftJoin(a.users,(0,t.eq)(a.userServers.userId,a.users.id)).where((0,t.eq)(a.userServers.serverId,e))).map(e=>({id:e.id,userId:e.userId,serverId:e.serverId,permission:e.permission,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user??void 0}))}async findByUser(e){return n.db.select().from(a.userServers).where((0,t.eq)(a.userServers.userId,e))}async create(e){let r=await n.db.insert(a.userServers).values(e).returning();if(!r[0])throw Error("Failed to create user-server permission");return r[0]}async updatePermission(e,r){let s=await n.db.update(a.userServers).set({permission:r,updatedAt:new Date}).where((0,t.eq)(a.userServers.id,e)).returning();if(!s[0])throw Error(`User-server permission not found: ${e}`);return s[0]}async delete(e){await n.db.delete(a.userServers).where((0,t.eq)(a.userServers.id,e))}async deleteByUserAndServer(e,r){await n.db.delete(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r)))}async countByServerAndPermission(e,r){return(await n.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.serverId,e),(0,t.eq)(a.userServers.permission,r)))).length}}},60154:(e,r,s)=>{s.d(r,{Ke:()=>c,kF:()=>u,l4:()=>o,mk:()=>d});var t=s(31969),n=s(22587),a=s(8290),i=s(30579);class o extends Error{constructor(e,r=401){super(e),this.statusCode=r,this.name="AuthError"}}async function d(e){let r=await t.I.api.getSession({headers:e});if(!r)throw new o("Unauthorized",401);return r}async function u(e){let r=await d(e);if("admin"!==r.user.role)throw new o("Forbidden: Admin access required",403);return r}async function c(e,r,s="view"){let t=await d(e);if("admin"===t.user.role)return t;let u=await n.db.select().from(a.userServers).where((0,i.xD)((0,i.eq)(a.userServers.userId,t.user.id),(0,i.eq)(a.userServers.serverId,r))).limit(1);if(0===u.length)throw new o("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[s])throw new o(`Forbidden: Requires ${s} permission`,403);return t}},31969:(e,r,s)=>{s.d(r,{I:()=>d});var t=s(33580),n=s(5944),a=s(90224),i=s(22587),o=s(8290);let d=(0,t.kj)({database:(0,n.s)(i.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,a.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,r,s)=>{s.d(r,{db:()=>p});var t=s(85890),n=s.n(t),a=s(31590),i=s(8290),o=s(55315),d=s.n(o),u=s(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),r=d().join(e,"data");return d().join(r,"mcctl.db")}();!function(e){if(":memory:"===e)return;let r=d().dirname(e);(0,u.existsSync)(r)||(0,u.mkdirSync)(r,{recursive:!0})}(c);let l=new(n())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
1
+ "use strict";(()=>{var e={};e.id=6222,e.ids=[6222],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},4908:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>L,patchFetch:()=>S,requestAsyncStorage:()=>E,routeModule:()=>T,serverHooks:()=>N,staticGenerationAsyncStorage:()=>y});var t={};s.r(t),s.d(t,{GET:()=>h,POST:()=>v,dynamic:()=>m});var n=s(3025),a=s(45086),i=s(74048),o=s(24517),d=s(78649),u=s(60154),c=s(77605),l=s(97060),p=s(74888);let m="force-dynamic";function f(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function h(){try{let e=await (0,u.mk)(await (0,c.headers)()),r=(0,d.F0)(f(e)),s=await r.getServers();if("admin"===e.user.role)return o.NextResponse.json(s);let t=new l.x,n=await t.findByUser(e.user.id),a=new Set(n.map(e=>e.serverId)),i=s.servers.filter(e=>a.has(e.name));return o.NextResponse.json({servers:i,total:i.length})}catch(e){if(e instanceof u.l4)return o.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return o.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch servers:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to fetch servers"},{status:500})}}async function v(e){try{let r=await (0,u.mk)(await (0,c.headers)()),s=await e.json(),t=(0,d.F0)(f(r)),n=await t.createServer(s);if("admin"!==r.user.role){let e=new l.x,s=new p.e(e);try{await s.grantAccess(r.user.id,n.server.name,"admin")}catch(e){console.error("Failed to grant admin permission:",e)}}return o.NextResponse.json(n,{status:201})}catch(e){if(e instanceof u.l4)return o.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return o.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to create server:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to create server"},{status:500})}}let T=new n.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/servers/route",pathname:"/api/servers",filename:"route",bundlePath:"app/api/servers/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/servers/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:E,staticGenerationAsyncStorage:y,serverHooks:N}=T,L="/api/servers/route";function S(){return(0,i.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:y})}},78649:(e,r,s)=>{s.d(r,{F0:()=>a,zB:()=>t});class t extends Error{constructor(e,r,s){super(s),this.statusCode=e,this.error=r,this.name="McctlApiError"}}class n{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,r={}){let s=`${this.baseUrl}${e}`,n={"X-API-Key":this.apiKey};r.body&&(n["Content-Type"]="application/json"),this.userContext&&(n["X-User"]=this.userContext.username,n["X-Role"]=this.userContext.role);let a=await fetch(s,{...r,headers:{...n,...r.headers}});if(!a.ok){let e=await a.json().catch(()=>({error:"UnknownError",message:a.statusText}));throw new t(a.status,e.error,e.message)}return a.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,r){return this.fetch(`/api/servers/${encodeURIComponent(e)}${r?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,r){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:r})})}async getLogs(e,r=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${r}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,r){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:r})})}async releaseWorld(e,r){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${r?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,r){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${r?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,r){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(r)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let r=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:r})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function a(e){let r=process.env.MCCTL_API_URL||"http://localhost:5001",s=process.env.MCCTL_API_KEY||"";return s||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new n({baseUrl:r,apiKey:s,userContext:e})}},97060:(e,r,s)=>{s.d(r,{x:()=>i});var t=s(30579),n=s(22587),a=s(8290);class i{async findById(e){return(await n.db.select().from(a.userServers).where((0,t.eq)(a.userServers.id,e)).limit(1))[0]??null}async findByUserAndServer(e,r){return(await n.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r))).limit(1))[0]??null}async findByServer(e){return n.db.select().from(a.userServers).where((0,t.eq)(a.userServers.serverId,e))}async findByServerWithUsers(e){return(await n.db.select({id:a.userServers.id,userId:a.userServers.userId,serverId:a.userServers.serverId,permission:a.userServers.permission,createdAt:a.userServers.createdAt,updatedAt:a.userServers.updatedAt,user:{id:a.users.id,name:a.users.name,email:a.users.email,image:a.users.image}}).from(a.userServers).leftJoin(a.users,(0,t.eq)(a.userServers.userId,a.users.id)).where((0,t.eq)(a.userServers.serverId,e))).map(e=>({id:e.id,userId:e.userId,serverId:e.serverId,permission:e.permission,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user??void 0}))}async findByUser(e){return n.db.select().from(a.userServers).where((0,t.eq)(a.userServers.userId,e))}async create(e){let r=await n.db.insert(a.userServers).values(e).returning();if(!r[0])throw Error("Failed to create user-server permission");return r[0]}async updatePermission(e,r){let s=await n.db.update(a.userServers).set({permission:r,updatedAt:new Date}).where((0,t.eq)(a.userServers.id,e)).returning();if(!s[0])throw Error(`User-server permission not found: ${e}`);return s[0]}async delete(e){await n.db.delete(a.userServers).where((0,t.eq)(a.userServers.id,e))}async deleteByUserAndServer(e,r){await n.db.delete(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r)))}async countByServerAndPermission(e,r){return(await n.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.serverId,e),(0,t.eq)(a.userServers.permission,r)))).length}}},60154:(e,r,s)=>{s.d(r,{Ke:()=>c,kF:()=>u,l4:()=>o,mk:()=>d});var t=s(31969),n=s(22587),a=s(8290),i=s(30579);class o extends Error{constructor(e,r=401){super(e),this.statusCode=r,this.name="AuthError"}}async function d(e){let r=await t.I.api.getSession({headers:e});if(!r)throw new o("Unauthorized",401);return r}async function u(e){let r=await d(e);if("admin"!==r.user.role)throw new o("Forbidden: Admin access required",403);return r}async function c(e,r,s="view"){let t=await d(e);if("admin"===t.user.role)return t;let u=await n.db.select().from(a.userServers).where((0,i.xD)((0,i.eq)(a.userServers.userId,t.user.id),(0,i.eq)(a.userServers.serverId,r))).limit(1);if(0===u.length)throw new o("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[s])throw new o(`Forbidden: Requires ${s} permission`,403);return t}},31969:(e,r,s)=>{s.d(r,{I:()=>c});var t=s(33580),n=s(5944),a=s(90224),i=s(22587),o=s(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,t.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,n.s)(i.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,a.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,r,s)=>{s.d(r,{db:()=>p});var t=s(85890),n=s.n(t),a=s(31590),i=s(8290),o=s(55315),d=s.n(o),u=s(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),r=d().join(e,"data");return d().join(r,"mcctl.db")}();!function(e){if(":memory:"===e)return;let r=d().dirname(e);(0,u.existsSync)(r)||(0,u.mkdirSync)(r,{recursive:!0})}(c);let l=new(n())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=8384,e.ids=[8384],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},77561:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>v,routeModule:()=>E,serverHooks:()=>N,staticGenerationAsyncStorage:()=>f});var t={};s.r(t),s.d(t,{DELETE:()=>T,PATCH:()=>p,dynamic:()=>c});var i=s(3025),a=s(45086),n=s(74048),o=s(24517),d=s(31969),u=s(77605),l=s(97060),m=s(74888);let c="force-dynamic";async function p(e,{params:r}){try{let s=await d.I.api.getSession({headers:await (0,u.headers)()});if(!s)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let{id:t}=await r,{permission:i}=await e.json();if(!i||!["view","manage","admin"].includes(i))return o.NextResponse.json({error:"BadRequest",message:"Permission must be view, manage, or admin"},{status:400});let a=function(){let e=new l.x;return new m.e(e)}(),n=new l.x,c=await n.findById(t);if(!c)return o.NextResponse.json({error:"NotFound",message:"Permission record not found"},{status:404});if("admin"!==s.user.role&&!await a.hasPermission(s.user.id,c.serverId,"admin"))return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403});let p=await a.updatePermission(c.userId,c.serverId,i);return o.NextResponse.json(p)}catch(e){if(e instanceof m.o)return o.NextResponse.json({error:"Forbidden",message:e.message},{status:403});return console.error("Failed to update permission:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to update permission"},{status:500})}}async function T(e,{params:r}){try{let e=await d.I.api.getSession({headers:await (0,u.headers)()});if(!e)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let{id:s}=await r;if("admin"!==e.user.role)return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403});let t=new l.x;return await t.delete(s),o.NextResponse.json({success:!0})}catch(e){if(e instanceof m.o)return o.NextResponse.json({error:"Forbidden",message:e.message},{status:403});return console.error("Failed to revoke access:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to revoke access"},{status:500})}}let E=new i.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/user-servers/[id]/route",pathname:"/api/user-servers/[id]",filename:"route",bundlePath:"app/api/user-servers/[id]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/user-servers/[id]/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:v,staticGenerationAsyncStorage:f,serverHooks:N}=E,L="/api/user-servers/[id]/route";function _(){return(0,n.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:f})}},97060:(e,r,s)=>{s.d(r,{x:()=>n});var t=s(30579),i=s(22587),a=s(8290);class n{async findById(e){return(await i.db.select().from(a.userServers).where((0,t.eq)(a.userServers.id,e)).limit(1))[0]??null}async findByUserAndServer(e,r){return(await i.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r))).limit(1))[0]??null}async findByServer(e){return i.db.select().from(a.userServers).where((0,t.eq)(a.userServers.serverId,e))}async findByServerWithUsers(e){return(await i.db.select({id:a.userServers.id,userId:a.userServers.userId,serverId:a.userServers.serverId,permission:a.userServers.permission,createdAt:a.userServers.createdAt,updatedAt:a.userServers.updatedAt,user:{id:a.users.id,name:a.users.name,email:a.users.email,image:a.users.image}}).from(a.userServers).leftJoin(a.users,(0,t.eq)(a.userServers.userId,a.users.id)).where((0,t.eq)(a.userServers.serverId,e))).map(e=>({id:e.id,userId:e.userId,serverId:e.serverId,permission:e.permission,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user??void 0}))}async findByUser(e){return i.db.select().from(a.userServers).where((0,t.eq)(a.userServers.userId,e))}async create(e){let r=await i.db.insert(a.userServers).values(e).returning();if(!r[0])throw Error("Failed to create user-server permission");return r[0]}async updatePermission(e,r){let s=await i.db.update(a.userServers).set({permission:r,updatedAt:new Date}).where((0,t.eq)(a.userServers.id,e)).returning();if(!s[0])throw Error(`User-server permission not found: ${e}`);return s[0]}async delete(e){await i.db.delete(a.userServers).where((0,t.eq)(a.userServers.id,e))}async deleteByUserAndServer(e,r){await i.db.delete(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r)))}async countByServerAndPermission(e,r){return(await i.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.serverId,e),(0,t.eq)(a.userServers.permission,r)))).length}}},31969:(e,r,s)=>{s.d(r,{I:()=>d});var t=s(33580),i=s(5944),a=s(90224),n=s(22587),o=s(8290);let d=(0,t.kj)({database:(0,i.s)(n.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,a.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,r,s)=>{s.d(r,{db:()=>c});var t=s(85890),i=s.n(t),a=s(31590),n=s(8290),o=s(55315),d=s.n(o),u=s(92048);let l=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),r=d().join(e,"data");return d().join(r,"mcctl.db")}();!function(e){if(":memory:"===e)return;let r=d().dirname(e);(0,u.existsSync)(r)||(0,u.mkdirSync)(r,{recursive:!0})}(l);let m=new(i())(l);m.pragma("journal_mode = WAL"),m.pragma("foreign_keys = ON"),m.exec(`
1
+ "use strict";(()=>{var e={};e.id=8384,e.ids=[8384],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},77561:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>v,routeModule:()=>E,serverHooks:()=>N,staticGenerationAsyncStorage:()=>f});var t={};s.r(t),s.d(t,{DELETE:()=>T,PATCH:()=>p,dynamic:()=>m});var i=s(3025),a=s(45086),n=s(74048),o=s(24517),d=s(31969),u=s(77605),c=s(97060),l=s(74888);let m="force-dynamic";async function p(e,{params:r}){try{let s=await d.I.api.getSession({headers:await (0,u.headers)()});if(!s)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let{id:t}=await r,{permission:i}=await e.json();if(!i||!["view","manage","admin"].includes(i))return o.NextResponse.json({error:"BadRequest",message:"Permission must be view, manage, or admin"},{status:400});let a=function(){let e=new c.x;return new l.e(e)}(),n=new c.x,m=await n.findById(t);if(!m)return o.NextResponse.json({error:"NotFound",message:"Permission record not found"},{status:404});if("admin"!==s.user.role&&!await a.hasPermission(s.user.id,m.serverId,"admin"))return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403});let p=await a.updatePermission(m.userId,m.serverId,i);return o.NextResponse.json(p)}catch(e){if(e instanceof l.o)return o.NextResponse.json({error:"Forbidden",message:e.message},{status:403});return console.error("Failed to update permission:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to update permission"},{status:500})}}async function T(e,{params:r}){try{let e=await d.I.api.getSession({headers:await (0,u.headers)()});if(!e)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let{id:s}=await r;if("admin"!==e.user.role)return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403});let t=new c.x;return await t.delete(s),o.NextResponse.json({success:!0})}catch(e){if(e instanceof l.o)return o.NextResponse.json({error:"Forbidden",message:e.message},{status:403});return console.error("Failed to revoke access:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to revoke access"},{status:500})}}let E=new i.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/user-servers/[id]/route",pathname:"/api/user-servers/[id]",filename:"route",bundlePath:"app/api/user-servers/[id]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/user-servers/[id]/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:v,staticGenerationAsyncStorage:f,serverHooks:N}=E,L="/api/user-servers/[id]/route";function _(){return(0,n.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:f})}},97060:(e,r,s)=>{s.d(r,{x:()=>n});var t=s(30579),i=s(22587),a=s(8290);class n{async findById(e){return(await i.db.select().from(a.userServers).where((0,t.eq)(a.userServers.id,e)).limit(1))[0]??null}async findByUserAndServer(e,r){return(await i.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r))).limit(1))[0]??null}async findByServer(e){return i.db.select().from(a.userServers).where((0,t.eq)(a.userServers.serverId,e))}async findByServerWithUsers(e){return(await i.db.select({id:a.userServers.id,userId:a.userServers.userId,serverId:a.userServers.serverId,permission:a.userServers.permission,createdAt:a.userServers.createdAt,updatedAt:a.userServers.updatedAt,user:{id:a.users.id,name:a.users.name,email:a.users.email,image:a.users.image}}).from(a.userServers).leftJoin(a.users,(0,t.eq)(a.userServers.userId,a.users.id)).where((0,t.eq)(a.userServers.serverId,e))).map(e=>({id:e.id,userId:e.userId,serverId:e.serverId,permission:e.permission,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user??void 0}))}async findByUser(e){return i.db.select().from(a.userServers).where((0,t.eq)(a.userServers.userId,e))}async create(e){let r=await i.db.insert(a.userServers).values(e).returning();if(!r[0])throw Error("Failed to create user-server permission");return r[0]}async updatePermission(e,r){let s=await i.db.update(a.userServers).set({permission:r,updatedAt:new Date}).where((0,t.eq)(a.userServers.id,e)).returning();if(!s[0])throw Error(`User-server permission not found: ${e}`);return s[0]}async delete(e){await i.db.delete(a.userServers).where((0,t.eq)(a.userServers.id,e))}async deleteByUserAndServer(e,r){await i.db.delete(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.userId,e),(0,t.eq)(a.userServers.serverId,r)))}async countByServerAndPermission(e,r){return(await i.db.select().from(a.userServers).where((0,t.xD)((0,t.eq)(a.userServers.serverId,e),(0,t.eq)(a.userServers.permission,r)))).length}}},31969:(e,r,s)=>{s.d(r,{I:()=>c});var t=s(33580),i=s(5944),a=s(90224),n=s(22587),o=s(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,t.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,i.s)(n.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,a.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,r,s)=>{s.d(r,{db:()=>m});var t=s(85890),i=s.n(t),a=s(31590),n=s(8290),o=s(55315),d=s.n(o),u=s(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),r=d().join(e,"data");return d().join(r,"mcctl.db")}();!function(e){if(":memory:"===e)return;let r=d().dirname(e);(0,u.existsSync)(r)||(0,u.mkdirSync)(r,{recursive:!0})}(c);let l=new(i())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -54,4 +54,4 @@ CREATE TABLE IF NOT EXISTS user_servers (
54
54
  updated_at INTEGER NOT NULL
55
55
  );
56
56
  CREATE INDEX IF NOT EXISTS user_server_idx ON user_servers(user_id, server_id);
57
- `);let c=(0,a.t)(m,{schema:n})},8290:(e,r,s)=>{s.r(r),s.d(r,{accounts:()=>u,sessions:()=>d,userServers:()=>m,users:()=>o,verifications:()=>l});var t=s(80722),i=s(10160),a=s(30304),n=s(76303);let o=(0,t.Px)("users",{id:(0,i.fL)("id").primaryKey(),name:(0,i.fL)("name").notNull(),email:(0,i.fL)("email").notNull().unique(),emailVerified:(0,a._L)("email_verified",{mode:"boolean"}).notNull().default(!1),image:(0,i.fL)("image"),role:(0,i.fL)("role").notNull().default("user"),banned:(0,a._L)("banned",{mode:"boolean"}).default(!1),banReason:(0,i.fL)("ban_reason"),banExpires:(0,a._L)("ban_expires",{mode:"timestamp"}),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),d=(0,t.Px)("sessions",{id:(0,i.fL)("id").primaryKey(),expiresAt:(0,a._L)("expires_at",{mode:"timestamp"}).notNull(),token:(0,i.fL)("token").notNull().unique(),ipAddress:(0,i.fL)("ip_address"),userAgent:(0,i.fL)("user_agent"),userId:(0,i.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,t.Px)("accounts",{id:(0,i.fL)("id").primaryKey(),accountId:(0,i.fL)("account_id").notNull(),providerId:(0,i.fL)("provider_id").notNull(),userId:(0,i.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),accessToken:(0,i.fL)("access_token"),refreshToken:(0,i.fL)("refresh_token"),idToken:(0,i.fL)("id_token"),accessTokenExpiresAt:(0,a._L)("access_token_expires_at",{mode:"timestamp"}),refreshTokenExpiresAt:(0,a._L)("refresh_token_expires_at",{mode:"timestamp"}),scope:(0,i.fL)("scope"),password:(0,i.fL)("password"),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),l=(0,t.Px)("verifications",{id:(0,i.fL)("id").primaryKey(),identifier:(0,i.fL)("identifier").notNull(),value:(0,i.fL)("value").notNull(),expiresAt:(0,a._L)("expires_at",{mode:"timestamp"}).notNull(),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).$defaultFn(()=>new Date)}),m=(0,t.Px)("user_servers",{id:(0,i.fL)("id").primaryKey().$defaultFn(()=>crypto.randomUUID()),userId:(0,i.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),serverId:(0,i.fL)("server_id").notNull(),permission:(0,i.fL)("permission").$type().notNull().default("view"),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>({userServerIdx:(0,n.Kz)("user_server_idx").on(e.userId,e.serverId)}))},74888:(e,r,s)=>{s.d(r,{e:()=>i,o:()=>t});class t extends Error{constructor(e){super(e),this.name="PermissionError"}}class i{constructor(e){this.repository=e}async grantAccess(e,r,s){let t=await this.repository.findByUserAndServer(e,r);return t?this.repository.updatePermission(t.id,s):this.repository.create({userId:e,serverId:r,permission:s})}async revokeAccess(e,r){let s=await this.repository.findByUserAndServer(e,r);if(s?.permission==="admin"&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot remove the last admin from the server");await this.repository.deleteByUserAndServer(e,r)}async updatePermission(e,r,s){let i=await this.repository.findByUserAndServer(e,r);if(!i)throw new t("Permission not found for this user and server");if("admin"===i.permission&&"admin"!==s&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot downgrade the last admin. Assign another admin first.");return this.repository.updatePermission(i.id,s)}async getServerUsers(e){return this.repository.findByServer(e)}async getServerUsersWithDetails(e){return this.repository.findByServerWithUsers(e)}async getUserServers(e){return this.repository.findByUser(e)}async hasPermission(e,r,s){let t=await this.repository.findByUserAndServer(e,r);if(!t)return!1;let i={view:1,manage:2,admin:3};return i[t.permission]>=i[s]}async ensureAtLeastOneAdmin(e){if(0===await this.repository.countByServerAndPermission(e,"admin"))throw new t("Server must have at least one admin")}}}};var r=require("../../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[9836,1489,7605,5309],()=>s(77561));module.exports=t})();
57
+ `);let m=(0,a.t)(l,{schema:n})},8290:(e,r,s)=>{s.r(r),s.d(r,{accounts:()=>u,sessions:()=>d,userServers:()=>l,users:()=>o,verifications:()=>c});var t=s(80722),i=s(10160),a=s(30304),n=s(76303);let o=(0,t.Px)("users",{id:(0,i.fL)("id").primaryKey(),name:(0,i.fL)("name").notNull(),email:(0,i.fL)("email").notNull().unique(),emailVerified:(0,a._L)("email_verified",{mode:"boolean"}).notNull().default(!1),image:(0,i.fL)("image"),role:(0,i.fL)("role").notNull().default("user"),banned:(0,a._L)("banned",{mode:"boolean"}).default(!1),banReason:(0,i.fL)("ban_reason"),banExpires:(0,a._L)("ban_expires",{mode:"timestamp"}),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),d=(0,t.Px)("sessions",{id:(0,i.fL)("id").primaryKey(),expiresAt:(0,a._L)("expires_at",{mode:"timestamp"}).notNull(),token:(0,i.fL)("token").notNull().unique(),ipAddress:(0,i.fL)("ip_address"),userAgent:(0,i.fL)("user_agent"),userId:(0,i.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,t.Px)("accounts",{id:(0,i.fL)("id").primaryKey(),accountId:(0,i.fL)("account_id").notNull(),providerId:(0,i.fL)("provider_id").notNull(),userId:(0,i.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),accessToken:(0,i.fL)("access_token"),refreshToken:(0,i.fL)("refresh_token"),idToken:(0,i.fL)("id_token"),accessTokenExpiresAt:(0,a._L)("access_token_expires_at",{mode:"timestamp"}),refreshTokenExpiresAt:(0,a._L)("refresh_token_expires_at",{mode:"timestamp"}),scope:(0,i.fL)("scope"),password:(0,i.fL)("password"),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),c=(0,t.Px)("verifications",{id:(0,i.fL)("id").primaryKey(),identifier:(0,i.fL)("identifier").notNull(),value:(0,i.fL)("value").notNull(),expiresAt:(0,a._L)("expires_at",{mode:"timestamp"}).notNull(),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).$defaultFn(()=>new Date)}),l=(0,t.Px)("user_servers",{id:(0,i.fL)("id").primaryKey().$defaultFn(()=>crypto.randomUUID()),userId:(0,i.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),serverId:(0,i.fL)("server_id").notNull(),permission:(0,i.fL)("permission").$type().notNull().default("view"),createdAt:(0,a._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,a._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>({userServerIdx:(0,n.Kz)("user_server_idx").on(e.userId,e.serverId)}))},74888:(e,r,s)=>{s.d(r,{e:()=>i,o:()=>t});class t extends Error{constructor(e){super(e),this.name="PermissionError"}}class i{constructor(e){this.repository=e}async grantAccess(e,r,s){let t=await this.repository.findByUserAndServer(e,r);return t?this.repository.updatePermission(t.id,s):this.repository.create({userId:e,serverId:r,permission:s})}async revokeAccess(e,r){let s=await this.repository.findByUserAndServer(e,r);if(s?.permission==="admin"&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot remove the last admin from the server");await this.repository.deleteByUserAndServer(e,r)}async updatePermission(e,r,s){let i=await this.repository.findByUserAndServer(e,r);if(!i)throw new t("Permission not found for this user and server");if("admin"===i.permission&&"admin"!==s&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot downgrade the last admin. Assign another admin first.");return this.repository.updatePermission(i.id,s)}async getServerUsers(e){return this.repository.findByServer(e)}async getServerUsersWithDetails(e){return this.repository.findByServerWithUsers(e)}async getUserServers(e){return this.repository.findByUser(e)}async hasPermission(e,r,s){let t=await this.repository.findByUserAndServer(e,r);if(!t)return!1;let i={view:1,manage:2,admin:3};return i[t.permission]>=i[s]}async ensureAtLeastOneAdmin(e){if(0===await this.repository.countByServerAndPermission(e,"admin"))throw new t("Server must have at least one admin")}}}};var r=require("../../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[9836,1489,7605,5309],()=>s(77561));module.exports=t})();
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=6185,e.ids=[6185],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},69903:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>_,patchFetch:()=>A,requestAsyncStorage:()=>f,routeModule:()=>v,serverHooks:()=>L,staticGenerationAsyncStorage:()=>N});var t={};s.r(t),s.d(t,{GET:()=>T,POST:()=>E,dynamic:()=>c});var a=s(3025),i=s(45086),n=s(74048),o=s(24517),d=s(31969),u=s(77605),l=s(97060),m=s(74888);let c="force-dynamic";function p(){let e=new l.x;return new m.e(e)}async function T(e){try{let r=await d.I.api.getSession({headers:await (0,u.headers)()});if(!r)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let s=e.nextUrl.searchParams.get("serverId");if(!s)return o.NextResponse.json({error:"BadRequest",message:"serverId query parameter is required"},{status:400});if("admin"!==r.user.role){let e=p();if(!await e.hasPermission(r.user.id,s,"admin"))return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403})}let t=p(),a=await t.getServerUsersWithDetails(s);return o.NextResponse.json({users:a,total:a.length})}catch(e){return console.error("Failed to list user-server permissions:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to list permissions"},{status:500})}}async function E(e){try{let r=await d.I.api.getSession({headers:await (0,u.headers)()});if(!r)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let{userId:s,serverId:t,permission:a}=await e.json();if(!s||!t||!a)return o.NextResponse.json({error:"BadRequest",message:"userId, serverId, and permission are required"},{status:400});if(!["view","manage","admin"].includes(a))return o.NextResponse.json({error:"BadRequest",message:"Permission must be view, manage, or admin"},{status:400});if("admin"!==r.user.role){let e=p();if(!await e.hasPermission(r.user.id,t,"admin"))return o.NextResponse.json({error:"Forbidden",message:"Admin permission required to grant access"},{status:403})}let i=p(),n=await i.grantAccess(s,t,a);return o.NextResponse.json(n,{status:201})}catch(e){if(e instanceof m.o)return o.NextResponse.json({error:"Forbidden",message:e.message},{status:403});return console.error("Failed to grant access:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to grant access"},{status:500})}}let v=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/user-servers/route",pathname:"/api/user-servers",filename:"route",bundlePath:"app/api/user-servers/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/user-servers/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:f,staticGenerationAsyncStorage:N,serverHooks:L}=v,_="/api/user-servers/route";function A(){return(0,n.patchFetch)({serverHooks:L,staticGenerationAsyncStorage:N})}},97060:(e,r,s)=>{s.d(r,{x:()=>n});var t=s(30579),a=s(22587),i=s(8290);class n{async findById(e){return(await a.db.select().from(i.userServers).where((0,t.eq)(i.userServers.id,e)).limit(1))[0]??null}async findByUserAndServer(e,r){return(await a.db.select().from(i.userServers).where((0,t.xD)((0,t.eq)(i.userServers.userId,e),(0,t.eq)(i.userServers.serverId,r))).limit(1))[0]??null}async findByServer(e){return a.db.select().from(i.userServers).where((0,t.eq)(i.userServers.serverId,e))}async findByServerWithUsers(e){return(await a.db.select({id:i.userServers.id,userId:i.userServers.userId,serverId:i.userServers.serverId,permission:i.userServers.permission,createdAt:i.userServers.createdAt,updatedAt:i.userServers.updatedAt,user:{id:i.users.id,name:i.users.name,email:i.users.email,image:i.users.image}}).from(i.userServers).leftJoin(i.users,(0,t.eq)(i.userServers.userId,i.users.id)).where((0,t.eq)(i.userServers.serverId,e))).map(e=>({id:e.id,userId:e.userId,serverId:e.serverId,permission:e.permission,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user??void 0}))}async findByUser(e){return a.db.select().from(i.userServers).where((0,t.eq)(i.userServers.userId,e))}async create(e){let r=await a.db.insert(i.userServers).values(e).returning();if(!r[0])throw Error("Failed to create user-server permission");return r[0]}async updatePermission(e,r){let s=await a.db.update(i.userServers).set({permission:r,updatedAt:new Date}).where((0,t.eq)(i.userServers.id,e)).returning();if(!s[0])throw Error(`User-server permission not found: ${e}`);return s[0]}async delete(e){await a.db.delete(i.userServers).where((0,t.eq)(i.userServers.id,e))}async deleteByUserAndServer(e,r){await a.db.delete(i.userServers).where((0,t.xD)((0,t.eq)(i.userServers.userId,e),(0,t.eq)(i.userServers.serverId,r)))}async countByServerAndPermission(e,r){return(await a.db.select().from(i.userServers).where((0,t.xD)((0,t.eq)(i.userServers.serverId,e),(0,t.eq)(i.userServers.permission,r)))).length}}},31969:(e,r,s)=>{s.d(r,{I:()=>d});var t=s(33580),a=s(5944),i=s(90224),n=s(22587),o=s(8290);let d=(0,t.kj)({database:(0,a.s)(n.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,i.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,r,s)=>{s.d(r,{db:()=>c});var t=s(85890),a=s.n(t),i=s(31590),n=s(8290),o=s(55315),d=s.n(o),u=s(92048);let l=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),r=d().join(e,"data");return d().join(r,"mcctl.db")}();!function(e){if(":memory:"===e)return;let r=d().dirname(e);(0,u.existsSync)(r)||(0,u.mkdirSync)(r,{recursive:!0})}(l);let m=new(a())(l);m.pragma("journal_mode = WAL"),m.pragma("foreign_keys = ON"),m.exec(`
1
+ "use strict";(()=>{var e={};e.id=6185,e.ids=[6185],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},69903:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>_,patchFetch:()=>A,requestAsyncStorage:()=>f,routeModule:()=>v,serverHooks:()=>L,staticGenerationAsyncStorage:()=>N});var t={};s.r(t),s.d(t,{GET:()=>T,POST:()=>E,dynamic:()=>m});var a=s(3025),i=s(45086),n=s(74048),o=s(24517),d=s(31969),u=s(77605),l=s(97060),c=s(74888);let m="force-dynamic";function p(){let e=new l.x;return new c.e(e)}async function T(e){try{let r=await d.I.api.getSession({headers:await (0,u.headers)()});if(!r)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let s=e.nextUrl.searchParams.get("serverId");if(!s)return o.NextResponse.json({error:"BadRequest",message:"serverId query parameter is required"},{status:400});if("admin"!==r.user.role){let e=p();if(!await e.hasPermission(r.user.id,s,"admin"))return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403})}let t=p(),a=await t.getServerUsersWithDetails(s);return o.NextResponse.json({users:a,total:a.length})}catch(e){return console.error("Failed to list user-server permissions:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to list permissions"},{status:500})}}async function E(e){try{let r=await d.I.api.getSession({headers:await (0,u.headers)()});if(!r)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});let{userId:s,serverId:t,permission:a}=await e.json();if(!s||!t||!a)return o.NextResponse.json({error:"BadRequest",message:"userId, serverId, and permission are required"},{status:400});if(!["view","manage","admin"].includes(a))return o.NextResponse.json({error:"BadRequest",message:"Permission must be view, manage, or admin"},{status:400});if("admin"!==r.user.role){let e=p();if(!await e.hasPermission(r.user.id,t,"admin"))return o.NextResponse.json({error:"Forbidden",message:"Admin permission required to grant access"},{status:403})}let i=p(),n=await i.grantAccess(s,t,a);return o.NextResponse.json(n,{status:201})}catch(e){if(e instanceof c.o)return o.NextResponse.json({error:"Forbidden",message:e.message},{status:403});return console.error("Failed to grant access:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to grant access"},{status:500})}}let v=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/user-servers/route",pathname:"/api/user-servers",filename:"route",bundlePath:"app/api/user-servers/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/user-servers/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:f,staticGenerationAsyncStorage:N,serverHooks:L}=v,_="/api/user-servers/route";function A(){return(0,n.patchFetch)({serverHooks:L,staticGenerationAsyncStorage:N})}},97060:(e,r,s)=>{s.d(r,{x:()=>n});var t=s(30579),a=s(22587),i=s(8290);class n{async findById(e){return(await a.db.select().from(i.userServers).where((0,t.eq)(i.userServers.id,e)).limit(1))[0]??null}async findByUserAndServer(e,r){return(await a.db.select().from(i.userServers).where((0,t.xD)((0,t.eq)(i.userServers.userId,e),(0,t.eq)(i.userServers.serverId,r))).limit(1))[0]??null}async findByServer(e){return a.db.select().from(i.userServers).where((0,t.eq)(i.userServers.serverId,e))}async findByServerWithUsers(e){return(await a.db.select({id:i.userServers.id,userId:i.userServers.userId,serverId:i.userServers.serverId,permission:i.userServers.permission,createdAt:i.userServers.createdAt,updatedAt:i.userServers.updatedAt,user:{id:i.users.id,name:i.users.name,email:i.users.email,image:i.users.image}}).from(i.userServers).leftJoin(i.users,(0,t.eq)(i.userServers.userId,i.users.id)).where((0,t.eq)(i.userServers.serverId,e))).map(e=>({id:e.id,userId:e.userId,serverId:e.serverId,permission:e.permission,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user??void 0}))}async findByUser(e){return a.db.select().from(i.userServers).where((0,t.eq)(i.userServers.userId,e))}async create(e){let r=await a.db.insert(i.userServers).values(e).returning();if(!r[0])throw Error("Failed to create user-server permission");return r[0]}async updatePermission(e,r){let s=await a.db.update(i.userServers).set({permission:r,updatedAt:new Date}).where((0,t.eq)(i.userServers.id,e)).returning();if(!s[0])throw Error(`User-server permission not found: ${e}`);return s[0]}async delete(e){await a.db.delete(i.userServers).where((0,t.eq)(i.userServers.id,e))}async deleteByUserAndServer(e,r){await a.db.delete(i.userServers).where((0,t.xD)((0,t.eq)(i.userServers.userId,e),(0,t.eq)(i.userServers.serverId,r)))}async countByServerAndPermission(e,r){return(await a.db.select().from(i.userServers).where((0,t.xD)((0,t.eq)(i.userServers.serverId,e),(0,t.eq)(i.userServers.permission,r)))).length}}},31969:(e,r,s)=>{s.d(r,{I:()=>l});var t=s(33580),a=s(5944),i=s(90224),n=s(22587),o=s(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),l=(0,t.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(n.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,i.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,r,s)=>{s.d(r,{db:()=>m});var t=s(85890),a=s.n(t),i=s(31590),n=s(8290),o=s(55315),d=s.n(o),u=s(92048);let l=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),r=d().join(e,"data");return d().join(r,"mcctl.db")}();!function(e){if(":memory:"===e)return;let r=d().dirname(e);(0,u.existsSync)(r)||(0,u.mkdirSync)(r,{recursive:!0})}(l);let c=new(a())(l);c.pragma("journal_mode = WAL"),c.pragma("foreign_keys = ON"),c.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -54,4 +54,4 @@ CREATE TABLE IF NOT EXISTS user_servers (
54
54
  updated_at INTEGER NOT NULL
55
55
  );
56
56
  CREATE INDEX IF NOT EXISTS user_server_idx ON user_servers(user_id, server_id);
57
- `);let c=(0,i.t)(m,{schema:n})},8290:(e,r,s)=>{s.r(r),s.d(r,{accounts:()=>u,sessions:()=>d,userServers:()=>m,users:()=>o,verifications:()=>l});var t=s(80722),a=s(10160),i=s(30304),n=s(76303);let o=(0,t.Px)("users",{id:(0,a.fL)("id").primaryKey(),name:(0,a.fL)("name").notNull(),email:(0,a.fL)("email").notNull().unique(),emailVerified:(0,i._L)("email_verified",{mode:"boolean"}).notNull().default(!1),image:(0,a.fL)("image"),role:(0,a.fL)("role").notNull().default("user"),banned:(0,i._L)("banned",{mode:"boolean"}).default(!1),banReason:(0,a.fL)("ban_reason"),banExpires:(0,i._L)("ban_expires",{mode:"timestamp"}),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),d=(0,t.Px)("sessions",{id:(0,a.fL)("id").primaryKey(),expiresAt:(0,i._L)("expires_at",{mode:"timestamp"}).notNull(),token:(0,a.fL)("token").notNull().unique(),ipAddress:(0,a.fL)("ip_address"),userAgent:(0,a.fL)("user_agent"),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,t.Px)("accounts",{id:(0,a.fL)("id").primaryKey(),accountId:(0,a.fL)("account_id").notNull(),providerId:(0,a.fL)("provider_id").notNull(),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),accessToken:(0,a.fL)("access_token"),refreshToken:(0,a.fL)("refresh_token"),idToken:(0,a.fL)("id_token"),accessTokenExpiresAt:(0,i._L)("access_token_expires_at",{mode:"timestamp"}),refreshTokenExpiresAt:(0,i._L)("refresh_token_expires_at",{mode:"timestamp"}),scope:(0,a.fL)("scope"),password:(0,a.fL)("password"),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),l=(0,t.Px)("verifications",{id:(0,a.fL)("id").primaryKey(),identifier:(0,a.fL)("identifier").notNull(),value:(0,a.fL)("value").notNull(),expiresAt:(0,i._L)("expires_at",{mode:"timestamp"}).notNull(),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).$defaultFn(()=>new Date)}),m=(0,t.Px)("user_servers",{id:(0,a.fL)("id").primaryKey().$defaultFn(()=>crypto.randomUUID()),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),serverId:(0,a.fL)("server_id").notNull(),permission:(0,a.fL)("permission").$type().notNull().default("view"),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>({userServerIdx:(0,n.Kz)("user_server_idx").on(e.userId,e.serverId)}))},74888:(e,r,s)=>{s.d(r,{e:()=>a,o:()=>t});class t extends Error{constructor(e){super(e),this.name="PermissionError"}}class a{constructor(e){this.repository=e}async grantAccess(e,r,s){let t=await this.repository.findByUserAndServer(e,r);return t?this.repository.updatePermission(t.id,s):this.repository.create({userId:e,serverId:r,permission:s})}async revokeAccess(e,r){let s=await this.repository.findByUserAndServer(e,r);if(s?.permission==="admin"&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot remove the last admin from the server");await this.repository.deleteByUserAndServer(e,r)}async updatePermission(e,r,s){let a=await this.repository.findByUserAndServer(e,r);if(!a)throw new t("Permission not found for this user and server");if("admin"===a.permission&&"admin"!==s&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot downgrade the last admin. Assign another admin first.");return this.repository.updatePermission(a.id,s)}async getServerUsers(e){return this.repository.findByServer(e)}async getServerUsersWithDetails(e){return this.repository.findByServerWithUsers(e)}async getUserServers(e){return this.repository.findByUser(e)}async hasPermission(e,r,s){let t=await this.repository.findByUserAndServer(e,r);if(!t)return!1;let a={view:1,manage:2,admin:3};return a[t.permission]>=a[s]}async ensureAtLeastOneAdmin(e){if(0===await this.repository.countByServerAndPermission(e,"admin"))throw new t("Server must have at least one admin")}}}};var r=require("../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[9836,1489,7605,5309],()=>s(69903));module.exports=t})();
57
+ `);let m=(0,i.t)(c,{schema:n})},8290:(e,r,s)=>{s.r(r),s.d(r,{accounts:()=>u,sessions:()=>d,userServers:()=>c,users:()=>o,verifications:()=>l});var t=s(80722),a=s(10160),i=s(30304),n=s(76303);let o=(0,t.Px)("users",{id:(0,a.fL)("id").primaryKey(),name:(0,a.fL)("name").notNull(),email:(0,a.fL)("email").notNull().unique(),emailVerified:(0,i._L)("email_verified",{mode:"boolean"}).notNull().default(!1),image:(0,a.fL)("image"),role:(0,a.fL)("role").notNull().default("user"),banned:(0,i._L)("banned",{mode:"boolean"}).default(!1),banReason:(0,a.fL)("ban_reason"),banExpires:(0,i._L)("ban_expires",{mode:"timestamp"}),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),d=(0,t.Px)("sessions",{id:(0,a.fL)("id").primaryKey(),expiresAt:(0,i._L)("expires_at",{mode:"timestamp"}).notNull(),token:(0,a.fL)("token").notNull().unique(),ipAddress:(0,a.fL)("ip_address"),userAgent:(0,a.fL)("user_agent"),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,t.Px)("accounts",{id:(0,a.fL)("id").primaryKey(),accountId:(0,a.fL)("account_id").notNull(),providerId:(0,a.fL)("provider_id").notNull(),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),accessToken:(0,a.fL)("access_token"),refreshToken:(0,a.fL)("refresh_token"),idToken:(0,a.fL)("id_token"),accessTokenExpiresAt:(0,i._L)("access_token_expires_at",{mode:"timestamp"}),refreshTokenExpiresAt:(0,i._L)("refresh_token_expires_at",{mode:"timestamp"}),scope:(0,a.fL)("scope"),password:(0,a.fL)("password"),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),l=(0,t.Px)("verifications",{id:(0,a.fL)("id").primaryKey(),identifier:(0,a.fL)("identifier").notNull(),value:(0,a.fL)("value").notNull(),expiresAt:(0,i._L)("expires_at",{mode:"timestamp"}).notNull(),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).$defaultFn(()=>new Date)}),c=(0,t.Px)("user_servers",{id:(0,a.fL)("id").primaryKey().$defaultFn(()=>crypto.randomUUID()),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),serverId:(0,a.fL)("server_id").notNull(),permission:(0,a.fL)("permission").$type().notNull().default("view"),createdAt:(0,i._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,i._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>({userServerIdx:(0,n.Kz)("user_server_idx").on(e.userId,e.serverId)}))},74888:(e,r,s)=>{s.d(r,{e:()=>a,o:()=>t});class t extends Error{constructor(e){super(e),this.name="PermissionError"}}class a{constructor(e){this.repository=e}async grantAccess(e,r,s){let t=await this.repository.findByUserAndServer(e,r);return t?this.repository.updatePermission(t.id,s):this.repository.create({userId:e,serverId:r,permission:s})}async revokeAccess(e,r){let s=await this.repository.findByUserAndServer(e,r);if(s?.permission==="admin"&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot remove the last admin from the server");await this.repository.deleteByUserAndServer(e,r)}async updatePermission(e,r,s){let a=await this.repository.findByUserAndServer(e,r);if(!a)throw new t("Permission not found for this user and server");if("admin"===a.permission&&"admin"!==s&&await this.repository.countByServerAndPermission(r,"admin")<=1)throw new t("Cannot downgrade the last admin. Assign another admin first.");return this.repository.updatePermission(a.id,s)}async getServerUsers(e){return this.repository.findByServer(e)}async getServerUsersWithDetails(e){return this.repository.findByServerWithUsers(e)}async getUserServers(e){return this.repository.findByUser(e)}async hasPermission(e,r,s){let t=await this.repository.findByUserAndServer(e,r);if(!t)return!1;let a={view:1,manage:2,admin:3};return a[t.permission]>=a[s]}async ensureAtLeastOneAdmin(e){if(0===await this.repository.countByServerAndPermission(e,"admin"))throw new t("Server must have at least one admin")}}}};var r=require("../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[9836,1489,7605,5309],()=>s(69903));module.exports=t})();
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=5701,e.ids=[5701],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},68249:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>A,requestAsyncStorage:()=>L,routeModule:()=>m,serverHooks:()=>_,staticGenerationAsyncStorage:()=>N});var s={};r.r(s),r.d(s,{GET:()=>c,dynamic:()=>p});var a=r(3025),n=r(45086),i=r(74048),d=r(24517),o=r(31969),u=r(77605),l=r(22587),T=r(8290),E=r(30579);let p="force-dynamic";async function c(e){try{let t=await o.I.api.getSession({headers:await (0,u.headers)()});if(!t)return d.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});if("admin"!==t.user.role)return d.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403});let r=e.nextUrl.searchParams.get("q");if(!r||r.length<2)return d.NextResponse.json({error:"BadRequest",message:"Search query must be at least 2 characters"},{status:400});let s=`%${r}%`,a=await l.db.select({id:T.users.id,name:T.users.name,email:T.users.email,image:T.users.image}).from(T.users).where((0,E.or)((0,E.vL)(T.users.name,s),(0,E.vL)(T.users.email,s))).limit(20);return d.NextResponse.json({users:a})}catch(e){return console.error("Failed to search users:",e),d.NextResponse.json({error:"InternalServerError",message:"Failed to search users"},{status:500})}}let m=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/users/route",pathname:"/api/users",filename:"route",bundlePath:"app/api/users/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/users/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:L,staticGenerationAsyncStorage:N,serverHooks:_}=m,f="/api/users/route";function A(){return(0,i.patchFetch)({serverHooks:_,staticGenerationAsyncStorage:N})}},31969:(e,t,r)=>{r.d(t,{I:()=>o});var s=r(33580),a=r(5944),n=r(90224),i=r(22587),d=r(8290);let o=(0,s.kj)({database:(0,a.s)(i.db,{provider:"sqlite",schema:{user:d.users,session:d.sessions,account:d.accounts,verification:d.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>E});var s=r(85890),a=r.n(s),n=r(31590),i=r(8290),d=r(55315),o=r.n(d),u=r(92048);let l=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=o().join(e,"data");return o().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=o().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(l);let T=new(a())(l);T.pragma("journal_mode = WAL"),T.pragma("foreign_keys = ON"),T.exec(`
1
+ "use strict";(()=>{var e={};e.id=5701,e.ids=[5701],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},68249:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>A,requestAsyncStorage:()=>L,routeModule:()=>m,serverHooks:()=>_,staticGenerationAsyncStorage:()=>N});var s={};r.r(s),r.d(s,{GET:()=>p,dynamic:()=>c});var a=r(3025),n=r(45086),i=r(74048),o=r(24517),d=r(31969),u=r(77605),l=r(22587),T=r(8290),E=r(30579);let c="force-dynamic";async function p(e){try{let t=await d.I.api.getSession({headers:await (0,u.headers)()});if(!t)return o.NextResponse.json({error:"Unauthorized",message:"Authentication required"},{status:401});if("admin"!==t.user.role)return o.NextResponse.json({error:"Forbidden",message:"Admin permission required"},{status:403});let r=e.nextUrl.searchParams.get("q");if(!r||r.length<2)return o.NextResponse.json({error:"BadRequest",message:"Search query must be at least 2 characters"},{status:400});let s=`%${r}%`,a=await l.db.select({id:T.users.id,name:T.users.name,email:T.users.email,image:T.users.image}).from(T.users).where((0,E.or)((0,E.vL)(T.users.name,s),(0,E.vL)(T.users.email,s))).limit(20);return o.NextResponse.json({users:a})}catch(e){return console.error("Failed to search users:",e),o.NextResponse.json({error:"InternalServerError",message:"Failed to search users"},{status:500})}}let m=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/users/route",pathname:"/api/users",filename:"route",bundlePath:"app/api/users/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/users/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:L,staticGenerationAsyncStorage:N,serverHooks:_}=m,f="/api/users/route";function A(){return(0,i.patchFetch)({serverHooks:_,staticGenerationAsyncStorage:N})}},31969:(e,t,r)=>{r.d(t,{I:()=>l});var s=r(33580),a=r(5944),n=r(90224),i=r(22587),o=r(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),l=(0,s.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(i.db,{provider:"sqlite",schema:{user:o.users,session:o.sessions,account:o.accounts,verification:o.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>E});var s=r(85890),a=r.n(s),n=r(31590),i=r(8290),o=r(55315),d=r.n(o),u=r(92048);let l=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(l);let T=new(a())(l);T.pragma("journal_mode = WAL"),T.pragma("foreign_keys = ON"),T.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -54,4 +54,4 @@ CREATE TABLE IF NOT EXISTS user_servers (
54
54
  updated_at INTEGER NOT NULL
55
55
  );
56
56
  CREATE INDEX IF NOT EXISTS user_server_idx ON user_servers(user_id, server_id);
57
- `);let E=(0,n.t)(T,{schema:i})},8290:(e,t,r)=>{r.r(t),r.d(t,{accounts:()=>u,sessions:()=>o,userServers:()=>T,users:()=>d,verifications:()=>l});var s=r(80722),a=r(10160),n=r(30304),i=r(76303);let d=(0,s.Px)("users",{id:(0,a.fL)("id").primaryKey(),name:(0,a.fL)("name").notNull(),email:(0,a.fL)("email").notNull().unique(),emailVerified:(0,n._L)("email_verified",{mode:"boolean"}).notNull().default(!1),image:(0,a.fL)("image"),role:(0,a.fL)("role").notNull().default("user"),banned:(0,n._L)("banned",{mode:"boolean"}).default(!1),banReason:(0,a.fL)("ban_reason"),banExpires:(0,n._L)("ban_expires",{mode:"timestamp"}),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),o=(0,s.Px)("sessions",{id:(0,a.fL)("id").primaryKey(),expiresAt:(0,n._L)("expires_at",{mode:"timestamp"}).notNull(),token:(0,a.fL)("token").notNull().unique(),ipAddress:(0,a.fL)("ip_address"),userAgent:(0,a.fL)("user_agent"),userId:(0,a.fL)("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,s.Px)("accounts",{id:(0,a.fL)("id").primaryKey(),accountId:(0,a.fL)("account_id").notNull(),providerId:(0,a.fL)("provider_id").notNull(),userId:(0,a.fL)("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),accessToken:(0,a.fL)("access_token"),refreshToken:(0,a.fL)("refresh_token"),idToken:(0,a.fL)("id_token"),accessTokenExpiresAt:(0,n._L)("access_token_expires_at",{mode:"timestamp"}),refreshTokenExpiresAt:(0,n._L)("refresh_token_expires_at",{mode:"timestamp"}),scope:(0,a.fL)("scope"),password:(0,a.fL)("password"),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),l=(0,s.Px)("verifications",{id:(0,a.fL)("id").primaryKey(),identifier:(0,a.fL)("identifier").notNull(),value:(0,a.fL)("value").notNull(),expiresAt:(0,n._L)("expires_at",{mode:"timestamp"}).notNull(),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).$defaultFn(()=>new Date)}),T=(0,s.Px)("user_servers",{id:(0,a.fL)("id").primaryKey().$defaultFn(()=>crypto.randomUUID()),userId:(0,a.fL)("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),serverId:(0,a.fL)("server_id").notNull(),permission:(0,a.fL)("permission").$type().notNull().default("view"),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>({userServerIdx:(0,i.Kz)("user_server_idx").on(e.userId,e.serverId)}))}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[9836,1489,7605,5309],()=>r(68249));module.exports=s})();
57
+ `);let E=(0,n.t)(T,{schema:i})},8290:(e,t,r)=>{r.r(t),r.d(t,{accounts:()=>u,sessions:()=>d,userServers:()=>T,users:()=>o,verifications:()=>l});var s=r(80722),a=r(10160),n=r(30304),i=r(76303);let o=(0,s.Px)("users",{id:(0,a.fL)("id").primaryKey(),name:(0,a.fL)("name").notNull(),email:(0,a.fL)("email").notNull().unique(),emailVerified:(0,n._L)("email_verified",{mode:"boolean"}).notNull().default(!1),image:(0,a.fL)("image"),role:(0,a.fL)("role").notNull().default("user"),banned:(0,n._L)("banned",{mode:"boolean"}).default(!1),banReason:(0,a.fL)("ban_reason"),banExpires:(0,n._L)("ban_expires",{mode:"timestamp"}),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),d=(0,s.Px)("sessions",{id:(0,a.fL)("id").primaryKey(),expiresAt:(0,n._L)("expires_at",{mode:"timestamp"}).notNull(),token:(0,a.fL)("token").notNull().unique(),ipAddress:(0,a.fL)("ip_address"),userAgent:(0,a.fL)("user_agent"),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,s.Px)("accounts",{id:(0,a.fL)("id").primaryKey(),accountId:(0,a.fL)("account_id").notNull(),providerId:(0,a.fL)("provider_id").notNull(),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),accessToken:(0,a.fL)("access_token"),refreshToken:(0,a.fL)("refresh_token"),idToken:(0,a.fL)("id_token"),accessTokenExpiresAt:(0,n._L)("access_token_expires_at",{mode:"timestamp"}),refreshTokenExpiresAt:(0,n._L)("refresh_token_expires_at",{mode:"timestamp"}),scope:(0,a.fL)("scope"),password:(0,a.fL)("password"),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),l=(0,s.Px)("verifications",{id:(0,a.fL)("id").primaryKey(),identifier:(0,a.fL)("identifier").notNull(),value:(0,a.fL)("value").notNull(),expiresAt:(0,n._L)("expires_at",{mode:"timestamp"}).notNull(),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).$defaultFn(()=>new Date)}),T=(0,s.Px)("user_servers",{id:(0,a.fL)("id").primaryKey().$defaultFn(()=>crypto.randomUUID()),userId:(0,a.fL)("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),serverId:(0,a.fL)("server_id").notNull(),permission:(0,a.fL)("permission").$type().notNull().default("view"),createdAt:(0,n._L)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,n._L)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>({userServerIdx:(0,i.Kz)("user_server_idx").on(e.userId,e.serverId)}))}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[9836,1489,7605,5309],()=>r(68249));module.exports=s})();
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=1914,e.ids=[1914],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},26482:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>h,requestAsyncStorage:()=>E,routeModule:()=>T,serverHooks:()=>N,staticGenerationAsyncStorage:()=>f});var s={};r.r(s),r.d(s,{POST:()=>m,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic",p=["assign","release"];async function m(e,{params:t}){try{let r=await (0,u.mk)(await (0,c.headers)()),{name:s,action:a}=await t;if(!p.includes(a))return i.NextResponse.json({error:"BadRequest",message:`Invalid action: ${a}`},{status:400});let n=(0,d.F0)({username:r.user.name||r.user.email,role:r.user.role||"user"});switch(a){case"assign":{let t=await e.json();if(!t.serverName)return i.NextResponse.json({error:"BadRequest",message:"serverName is required"},{status:400});let r=await n.assignWorld(s,t.serverName);return i.NextResponse.json(r)}case"release":{let{searchParams:t}=new URL(e.url),r="true"===t.get("force"),a=await n.releaseWorld(s,r);return i.NextResponse.json(a)}default:return i.NextResponse.json({error:"BadRequest",message:`Invalid action: ${a}`},{status:400})}}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to execute action:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to execute action"},{status:500})}}let T=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worlds/[name]/[action]/route",pathname:"/api/worlds/[name]/[action]",filename:"route",bundlePath:"app/api/worlds/[name]/[action]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/worlds/[name]/[action]/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:E,staticGenerationAsyncStorage:f,serverHooks:N}=T,L="/api/worlds/[name]/[action]/route";function h(){return(0,o.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:f})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>d});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=(0,s.kj)({database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
1
+ "use strict";(()=>{var e={};e.id=1914,e.ids=[1914],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},26482:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>L,requestAsyncStorage:()=>E,routeModule:()=>T,serverHooks:()=>N,staticGenerationAsyncStorage:()=>f});var s={};r.r(s),r.d(s,{POST:()=>m,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic",p=["assign","release"];async function m(e,{params:t}){try{let r=await (0,u.mk)(await (0,c.headers)()),{name:s,action:a}=await t;if(!p.includes(a))return i.NextResponse.json({error:"BadRequest",message:`Invalid action: ${a}`},{status:400});let n=(0,d.F0)({username:r.user.name||r.user.email,role:r.user.role||"user"});switch(a){case"assign":{let t=await e.json();if(!t.serverName)return i.NextResponse.json({error:"BadRequest",message:"serverName is required"},{status:400});let r=await n.assignWorld(s,t.serverName);return i.NextResponse.json(r)}case"release":{let{searchParams:t}=new URL(e.url),r="true"===t.get("force"),a=await n.releaseWorld(s,r);return i.NextResponse.json(a)}default:return i.NextResponse.json({error:"BadRequest",message:`Invalid action: ${a}`},{status:400})}}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to execute action:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to execute action"},{status:500})}}let T=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worlds/[name]/[action]/route",pathname:"/api/worlds/[name]/[action]",filename:"route",bundlePath:"app/api/worlds/[name]/[action]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/worlds/[name]/[action]/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:E,staticGenerationAsyncStorage:f,serverHooks:N}=T,h="/api/worlds/[name]/[action]/route";function L(){return(0,o.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:f})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>c});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,s.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=5746,e.ids=[5746],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},20062:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>f,routeModule:()=>E,serverHooks:()=>h,staticGenerationAsyncStorage:()=>N});var s={};r.r(s),r.d(s,{DELETE:()=>T,GET:()=>m,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";function p(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function m(e,{params:t}){try{let e=await (0,u.mk)(await (0,c.headers)()),{name:r}=await t,s=(0,d.F0)(p(e)),a=await s.getWorld(r);return i.NextResponse.json(a)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to fetch world details"},{status:500})}}async function T(e,{params:t}){try{let r=await (0,u.kF)(await (0,c.headers)()),{name:s}=await t,{searchParams:a}=new URL(e.url),n="true"===a.get("force"),o=(0,d.F0)(p(r)),l=await o.deleteWorld(s,n);return i.NextResponse.json(l)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to delete world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to delete world"},{status:500})}}let E=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worlds/[name]/route",pathname:"/api/worlds/[name]",filename:"route",bundlePath:"app/api/worlds/[name]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/worlds/[name]/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:f,staticGenerationAsyncStorage:N,serverHooks:h}=E,L="/api/worlds/[name]/route";function _(){return(0,o.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:N})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>d});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=(0,s.kj)({database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
1
+ "use strict";(()=>{var e={};e.id=5746,e.ids=[5746],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},20062:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>f,routeModule:()=>E,serverHooks:()=>N,staticGenerationAsyncStorage:()=>h});var s={};r.r(s),r.d(s,{DELETE:()=>T,GET:()=>m,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";function p(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function m(e,{params:t}){try{let e=await (0,u.mk)(await (0,c.headers)()),{name:r}=await t,s=(0,d.F0)(p(e)),a=await s.getWorld(r);return i.NextResponse.json(a)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to fetch world details"},{status:500})}}async function T(e,{params:t}){try{let r=await (0,u.kF)(await (0,c.headers)()),{name:s}=await t,{searchParams:a}=new URL(e.url),n="true"===a.get("force"),o=(0,d.F0)(p(r)),l=await o.deleteWorld(s,n);return i.NextResponse.json(l)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Forbidden",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to delete world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to delete world"},{status:500})}}let E=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worlds/[name]/route",pathname:"/api/worlds/[name]",filename:"route",bundlePath:"app/api/worlds/[name]/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/worlds/[name]/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:f,staticGenerationAsyncStorage:h,serverHooks:N}=E,L="/api/worlds/[name]/route";function _(){return(0,o.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:h})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>c});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,s.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=6541,e.ids=[6541],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},32527:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>f,routeModule:()=>E,serverHooks:()=>N,staticGenerationAsyncStorage:()=>h});var s={};r.r(s),r.d(s,{GET:()=>m,POST:()=>T,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";function p(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function m(){try{let e=await (0,u.mk)(await (0,c.headers)()),t=(0,d.F0)(p(e)),r=await t.getWorlds();return i.NextResponse.json(r)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch worlds:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to fetch worlds"},{status:500})}}async function T(e){try{let t=await (0,u.mk)(await (0,c.headers)()),r=await e.json(),s=(0,d.F0)(p(t)),a=await s.createWorld(r);return i.NextResponse.json(a,{status:201})}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to create world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to create world"},{status:500})}}let E=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worlds/route",pathname:"/api/worlds",filename:"route",bundlePath:"app/api/worlds/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/worlds/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:f,staticGenerationAsyncStorage:h,serverHooks:N}=E,L="/api/worlds/route";function _(){return(0,o.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:h})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>d});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=(0,s.kj)({database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",...process.env.BETTER_AUTH_BASE_URL?[process.env.BETTER_AUTH_BASE_URL]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
1
+ "use strict";(()=>{var e={};e.id=6541,e.ids=[6541],e.modules={85890:e=>{e.exports=require("better-sqlite3")},72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},92048:e=>{e.exports=require("fs")},55315:e=>{e.exports=require("path")},32527:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>L,patchFetch:()=>_,requestAsyncStorage:()=>f,routeModule:()=>E,serverHooks:()=>N,staticGenerationAsyncStorage:()=>h});var s={};r.r(s),r.d(s,{GET:()=>m,POST:()=>T,dynamic:()=>l});var a=r(3025),n=r(45086),o=r(74048),i=r(24517),d=r(78649),u=r(60154),c=r(77605);let l="force-dynamic";function p(e){return{username:e.user.name||e.user.email,role:e.user.role||"user"}}async function m(){try{let e=await (0,u.mk)(await (0,c.headers)()),t=(0,d.F0)(p(e)),r=await t.getWorlds();return i.NextResponse.json(r)}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to fetch worlds:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to fetch worlds"},{status:500})}}async function T(e){try{let t=await (0,u.mk)(await (0,c.headers)()),r=await e.json(),s=(0,d.F0)(p(t)),a=await s.createWorld(r);return i.NextResponse.json(a,{status:201})}catch(e){if(e instanceof u.l4)return i.NextResponse.json({error:"Unauthorized",message:e.message},{status:e.statusCode});if(e instanceof d.zB)return i.NextResponse.json({error:e.error,message:e.message},{status:e.statusCode});return console.error("Failed to create world:",e),i.NextResponse.json({error:"InternalServerError",message:"Failed to create world"},{status:500})}}let E=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worlds/route",pathname:"/api/worlds",filename:"route",bundlePath:"app/api/worlds/route"},resolvedPagePath:"/home/runner/work/minecraft-server-manager/minecraft-server-manager/platform/services/mcctl-console/src/app/api/worlds/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:f,staticGenerationAsyncStorage:h,serverHooks:N}=E,L="/api/worlds/route";function _(){return(0,o.patchFetch)({serverHooks:N,staticGenerationAsyncStorage:h})}},78649:(e,t,r)=>{r.d(t,{F0:()=>n,zB:()=>s});class s extends Error{constructor(e,t,r){super(r),this.statusCode=e,this.error=t,this.name="McctlApiError"}}class a{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey,this.userContext=e.userContext}async fetch(e,t={}){let r=`${this.baseUrl}${e}`,a={"X-API-Key":this.apiKey};t.body&&(a["Content-Type"]="application/json"),this.userContext&&(a["X-User"]=this.userContext.username,a["X-Role"]=this.userContext.role);let n=await fetch(r,{...t,headers:{...a,...t.headers}});if(!n.ok){let e=await n.json().catch(()=>({error:"UnknownError",message:n.statusText}));throw new s(n.status,e.error,e.message)}return n.json()}async getServers(){return this.fetch("/api/servers")}async getServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}`)}async createServer(e){return this.fetch("/api/servers",{method:"POST",body:JSON.stringify(e)})}async deleteServer(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async startServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/start`,{method:"POST"})}async stopServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/stop`,{method:"POST"})}async restartServer(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/restart`,{method:"POST"})}async execCommand(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/exec`,{method:"POST",body:JSON.stringify({command:t})})}async getLogs(e,t=100){return this.fetch(`/api/servers/${encodeURIComponent(e)}/logs?lines=${t}`)}async getWorlds(){return this.fetch("/api/worlds")}async getWorld(e){return this.fetch(`/api/worlds/${encodeURIComponent(e)}`)}async createWorld(e){return this.fetch("/api/worlds",{method:"POST",body:JSON.stringify(e)})}async assignWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/assign`,{method:"POST",body:JSON.stringify({serverName:t})})}async releaseWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}/release${t?"?force=true":""}`,{method:"POST"})}async deleteWorld(e,t){return this.fetch(`/api/worlds/${encodeURIComponent(e)}${t?"?force=true":""}`,{method:"DELETE"})}async getServerConfig(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`)}async updateServerConfig(e,t){return this.fetch(`/api/servers/${encodeURIComponent(e)}/config`,{method:"PATCH",body:JSON.stringify(t)})}async resetWorld(e){return this.fetch(`/api/servers/${encodeURIComponent(e)}/world/reset`,{method:"POST"})}async getRouterStatus(){return this.fetch("/api/router/status")}async getBackupStatus(){return this.fetch("/api/backup/status")}async pushBackup(e){let t=e?JSON.stringify({message:e}):void 0;return this.fetch("/api/backup/push",{method:"POST",body:t})}async getBackupHistory(e=20){return this.fetch(`/api/backup/history?limit=${e}`)}async restoreBackup(e){return this.fetch("/api/backup/restore",{method:"POST",body:JSON.stringify({commitHash:e})})}}function n(e){let t=process.env.MCCTL_API_URL||"http://localhost:5001",r=process.env.MCCTL_API_KEY||"";return r||console.warn("MCCTL_API_KEY is not set. API requests may fail."),new a({baseUrl:t,apiKey:r,userContext:e})}},60154:(e,t,r)=>{r.d(t,{Ke:()=>c,kF:()=>u,l4:()=>i,mk:()=>d});var s=r(31969),a=r(22587),n=r(8290),o=r(30579);class i extends Error{constructor(e,t=401){super(e),this.statusCode=t,this.name="AuthError"}}async function d(e){let t=await s.I.api.getSession({headers:e});if(!t)throw new i("Unauthorized",401);return t}async function u(e){let t=await d(e);if("admin"!==t.user.role)throw new i("Forbidden: Admin access required",403);return t}async function c(e,t,r="view"){let s=await d(e);if("admin"===s.user.role)return s;let u=await a.db.select().from(n.userServers).where((0,o.xD)((0,o.eq)(n.userServers.userId,s.user.id),(0,o.eq)(n.userServers.serverId,t))).limit(1);if(0===u.length)throw new i("Forbidden: No access to this server",403);let c=u[0].permission,l={view:1,manage:2,admin:3};if(l[c]<l[r])throw new i(`Forbidden: Requires ${r} permission`,403);return s}},31969:(e,t,r)=>{r.d(t,{I:()=>c});var s=r(33580),a=r(5944),n=r(90224),o=r(22587),i=r(8290);let d=process.env.BETTER_AUTH_BASE_URL||`http://localhost:${process.env.PORT||5e3}`,u=d.startsWith("https://"),c=(0,s.kj)({baseURL:d,secret:process.env.BETTER_AUTH_SECRET,database:(0,a.s)(o.db,{provider:"sqlite",schema:{user:i.users,session:i.sessions,account:i.accounts,verification:i.verifications}}),emailAndPassword:{enabled:!0,requireEmailVerification:!1},session:{expiresIn:604800,updateAge:86400,cookieCache:{enabled:!0,maxAge:300}},advanced:{useSecureCookies:u},user:{additionalFields:{role:{type:"string",required:!1,defaultValue:"user",input:!1}}},plugins:[(0,n.SA)({defaultRole:"user",adminRole:"admin"})],trustedOrigins:["http://localhost:5000","http://localhost:3000",..."http://localhost:5000"!==d?[d]:[],...process.env.NEXT_PUBLIC_APP_URL?[process.env.NEXT_PUBLIC_APP_URL]:[]]})},22587:(e,t,r)=>{r.d(t,{db:()=>p});var s=r(85890),a=r.n(s),n=r(31590),o=r(8290),i=r(55315),d=r.n(i),u=r(92048);let c=function(){if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.MCCTL_ROOT||process.cwd(),t=d().join(e,"data");return d().join(t,"mcctl.db")}();!function(e){if(":memory:"===e)return;let t=d().dirname(e);(0,u.existsSync)(t)||(0,u.mkdirSync)(t,{recursive:!0})}(c);let l=new(a())(c);l.pragma("journal_mode = WAL"),l.pragma("foreign_keys = ON"),l.exec(`
2
2
  CREATE TABLE IF NOT EXISTS users (
3
3
  id TEXT PRIMARY KEY,
4
4
  name TEXT NOT NULL,