import View from"./view.mjs";import sessions from"../../sessions.mjs";import Module from"../../packages/module.mjs";import System from"../../packages/system.mjs";import World from"../../packages/world.mjs";import*as packages from"../../packages/views.mjs";export default class CreateView extends View{route="/create";socket="getCreateData";_template="create";_methods=["get","post"];async handleGet(e,s){try{this.constructor.assertDocumentDestination(e)}catch(e){return s.status(401).send(e.message)}if(config.license.needsSignature)return s.redirect(`${e.baseUrl}/license`);if(game.world)return s.redirect(`${e.baseUrl}/${e.user?"game":"join"}`);if(!sessions.authenticateAdmin(e,s).success)return s.redirect(`${e.baseUrl}/auth`);const t=View._getStaticContent({setup:!0}),a={layout:"setup",bodyClass:["auth","create","flexcol",`theme-${config.options.cssTheme}`].join(" "),messages:sessions.getMessages(e,{clear:!0}),scripts:t.scripts,styles:t.styles};s.render(this._template,a)}async handlePost(e,s){if(!sessions.authenticateAdmin(e,s).success)return s.status(403).json({error:"You lack server administrator permission to submit this request."});let t={};try{switch(e.body.action){case"createWorld":t=World.create(e);break;case"getPackageFromRemoteManifest":t=await packages.getPackageFromRemoteManifest(e.body);break;case"getPackages":t=await packages.getPackages(e.body);break;case"installPackage":t=await packages.installPackage(e.body)}}catch(e){t={error:e.message,stack:e.stack}}return t.redirect?s.redirect(e.baseUrl+t.redirect):s.json(t)}async handleSocket(e,s){return config.adminPassword&&!e.admin||game.world?s({}):s({release:release,files:config.files.getClientConfig(),languages:Module.getCoreTranslationOptions(),modules:Module.getPackages().map(e=>e.vend()),options:{language:config.options.language},systems:System.getPackages().map(e=>e.vend()),worlds:World.getPackages().map(e=>e.vend())})}}