admin(ui): add all fields to createServer.ts

This commit is contained in:
Matthew Penner 2021-01-13 09:43:57 -07:00
parent c40e4bd2c0
commit d648ee5c93
3 changed files with 68 additions and 14 deletions

View File

@ -8,7 +8,6 @@ use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Services\Servers\ServerCreationService; use Pterodactyl\Services\Servers\ServerCreationService;
use Pterodactyl\Services\Servers\ServerDeletionService; use Pterodactyl\Services\Servers\ServerDeletionService;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\ServerTransformer; use Pterodactyl\Transformers\Api\Application\ServerTransformer;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest; use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest;
@ -29,28 +28,20 @@ class ServerController extends ApplicationApiController
*/ */
private $deletionService; private $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/** /**
* ServerController constructor. * ServerController constructor.
* *
* @param \Pterodactyl\Services\Servers\ServerCreationService $creationService * @param \Pterodactyl\Services\Servers\ServerCreationService $creationService
* @param \Pterodactyl\Services\Servers\ServerDeletionService $deletionService * @param \Pterodactyl\Services\Servers\ServerDeletionService $deletionService
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/ */
public function __construct( public function __construct(
ServerCreationService $creationService, ServerCreationService $creationService,
ServerDeletionService $deletionService, ServerDeletionService $deletionService
ServerRepositoryInterface $repository
) { ) {
parent::__construct(); parent::__construct();
$this->creationService = $creationService; $this->creationService = $creationService;
$this->deletionService = $deletionService; $this->deletionService = $deletionService;
$this->repository = $repository;
} }
/** /**

View File

@ -5,6 +5,7 @@ namespace Pterodactyl\Models;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Illuminate\Container\Container; use Illuminate\Container\Container;
use Illuminate\Validation\Validator;
use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\Factory;
use Illuminate\Database\Eloquent\Model as IlluminateModel; use Illuminate\Database\Eloquent\Model as IlluminateModel;
use Pterodactyl\Exceptions\Model\DataValidationException; use Pterodactyl\Exceptions\Model\DataValidationException;
@ -79,9 +80,9 @@ abstract class Model extends IlluminateModel
/** /**
* Returns the validator instance used by this model. * 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(); $rules = $this->getKey() ? static::getRulesForUpdate($this) : static::getRules();

View File

@ -1,10 +1,72 @@
import http from '@/api/http'; import http from '@/api/http';
import { Server, rawDataToServer } from '@/api/admin/servers/getServers'; import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
export default (name: string, description: string): Promise<Server> => { 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<Server> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.post('/api/application/servers', { 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))) .then(({ data }) => resolve(rawDataToServer(data)))
.catch(reject); .catch(reject);