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 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;
}
/**

View file

@ -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();

View file

@ -1,10 +1,72 @@
import http from '@/api/http';
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) => {
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);