From d648ee5c931e20a50612536e0871eee788f19821 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 13 Jan 2021 09:43:57 -0700 Subject: [PATCH] admin(ui): add all fields to createServer.ts --- .../Application/Servers/ServerController.php | 11 +--- app/Models/Model.php | 5 +- .../scripts/api/admin/servers/createServer.ts | 66 ++++++++++++++++++- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Api/Application/Servers/ServerController.php b/app/Http/Controllers/Api/Application/Servers/ServerController.php index bf33b6bc..cdd96554 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerController.php @@ -8,7 +8,6 @@ use Illuminate\Http\JsonResponse; use Spatie\QueryBuilder\QueryBuilder; use Pterodactyl\Services\Servers\ServerCreationService; use Pterodactyl\Services\Servers\ServerDeletionService; -use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Pterodactyl\Transformers\Api\Application\ServerTransformer; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest; @@ -29,28 +28,20 @@ class ServerController extends ApplicationApiController */ private $deletionService; - /** - * @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface - */ - private $repository; - /** * ServerController constructor. * * @param \Pterodactyl\Services\Servers\ServerCreationService $creationService * @param \Pterodactyl\Services\Servers\ServerDeletionService $deletionService - * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository */ public function __construct( ServerCreationService $creationService, - ServerDeletionService $deletionService, - ServerRepositoryInterface $repository + ServerDeletionService $deletionService ) { parent::__construct(); $this->creationService = $creationService; $this->deletionService = $deletionService; - $this->repository = $repository; } /** diff --git a/app/Models/Model.php b/app/Models/Model.php index f6b94a3a..a050746b 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -5,6 +5,7 @@ namespace Pterodactyl\Models; use Illuminate\Support\Str; use Illuminate\Validation\Rule; use Illuminate\Container\Container; +use Illuminate\Validation\Validator; use Illuminate\Contracts\Validation\Factory; use Illuminate\Database\Eloquent\Model as IlluminateModel; use Pterodactyl\Exceptions\Model\DataValidationException; @@ -79,9 +80,9 @@ abstract class Model extends IlluminateModel /** * Returns the validator instance used by this model. * - * @return \Illuminate\Validation\Validator|\Illuminate\Contracts\Validation\Validator + * @return \Illuminate\Validation\Validator */ - public function getValidator() + public function getValidator(): Validator { $rules = $this->getKey() ? static::getRulesForUpdate($this) : static::getRules(); diff --git a/resources/scripts/api/admin/servers/createServer.ts b/resources/scripts/api/admin/servers/createServer.ts index 39aa6848..fd64dcbd 100644 --- a/resources/scripts/api/admin/servers/createServer.ts +++ b/resources/scripts/api/admin/servers/createServer.ts @@ -1,10 +1,72 @@ import http from '@/api/http'; import { Server, rawDataToServer } from '@/api/admin/servers/getServers'; -export default (name: string, description: string): Promise => { +interface CreateServerRequest { + name: string; + description: string | null; + user: number; + egg: number; + dockerImage: string; + startup: string; + skipScripts: boolean; + oomDisabled: boolean; + startOnCompletion: boolean; + environment: string[]; + + allocation: { + default: number; + additional: number[]; + }; + + limits: { + cpu: number; + disk: number; + io: number; + memory: number; + swap: number; + threads: string; + }; + + featureLimits: { + allocations: number; + backups: number; + databases: number; + }; +} + +export default (r: CreateServerRequest): Promise => { return new Promise((resolve, reject) => { http.post('/api/application/servers', { - name, description, + name: r.name, + description: r.description, + user: r.user, + egg: r.egg, + docker_image: r.dockerImage, + startup: r.startup, + skip_scripts: r.skipScripts, + oom_disabled: r.oomDisabled, + start_on_completion: r.startOnCompletion, + environment: r.environment, + + allocation: { + default: r.allocation.default, + additional: r.allocation.additional, + }, + + limits: { + cpu: r.limits.cpu, + disk: r.limits.disk, + io: r.limits.io, + memory: r.limits.memory, + swap: r.limits.swap, + threads: r.limits.threads, + }, + + featureLimits: { + allocations: r.featureLimits.allocations, + backups: r.featureLimits.backups, + databases: r.featureLimits.databases, + }, }) .then(({ data }) => resolve(rawDataToServer(data))) .catch(reject);