Merge branch 'develop' into dane/restore-backups
This commit is contained in:
commit
be26921fcc
41 changed files with 440 additions and 362 deletions
|
@ -3,6 +3,8 @@
|
|||
namespace Pterodactyl\Services\Eggs\Sharing;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
|
||||
class EggExporterService
|
||||
|
@ -41,7 +43,9 @@ class EggExporterService
|
|||
'description' => $egg->description,
|
||||
'features' => $egg->features,
|
||||
'images' => $egg->docker_images,
|
||||
'file_denylist' => $egg->inherit_file_denylist,
|
||||
'file_denylist' => Collection::make($egg->inherit_file_denylist)->filter(function ($value) {
|
||||
return !empty($value);
|
||||
}),
|
||||
'startup' => $egg->startup,
|
||||
'config' => [
|
||||
'files' => $egg->inherit_config_files,
|
||||
|
@ -56,10 +60,10 @@ class EggExporterService
|
|||
'entrypoint' => $egg->copy_script_entry,
|
||||
],
|
||||
],
|
||||
'variables' => $egg->variables->transform(function ($item) {
|
||||
return collect($item->toArray())->except([
|
||||
'id', 'egg_id', 'created_at', 'updated_at',
|
||||
])->toArray();
|
||||
'variables' => $egg->variables->transform(function (EggVariable $item) {
|
||||
return Collection::make($item->toArray())
|
||||
->except(['id', 'egg_id', 'created_at', 'updated_at'])
|
||||
->toArray();
|
||||
}),
|
||||
];
|
||||
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
namespace Pterodactyl\Services\Eggs\Sharing;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Support\Arr;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
|
@ -63,43 +65,47 @@ class EggImporterService
|
|||
throw new InvalidFileUploadException(sprintf('The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)', $file->getFilename(), $file->isFile() ? 'true' : 'false', $file->isValid() ? 'true' : 'false', $file->getError(), $file->getErrorMessage()));
|
||||
}
|
||||
|
||||
$parsed = json_decode($file->openFile()->fread($file->getSize()));
|
||||
/** @var array $parsed */
|
||||
$parsed = json_decode($file->openFile()->fread($file->getSize()), true);
|
||||
if (json_last_error() !== 0) {
|
||||
throw new BadJsonFormatException(trans('exceptions.nest.importer.json_error', ['error' => json_last_error_msg()]));
|
||||
}
|
||||
|
||||
if (object_get($parsed, 'meta.version') !== 'PTDL_v1') {
|
||||
if (Arr::get($parsed, 'meta.version') !== 'PTDL_v1') {
|
||||
throw new InvalidFileUploadException(trans('exceptions.nest.importer.invalid_json_provided'));
|
||||
}
|
||||
|
||||
$nest = $this->nestRepository->getWithEggs($nest);
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
/** @var \Pterodactyl\Models\Egg $egg */
|
||||
$egg = $this->repository->create([
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'nest_id' => $nest->id,
|
||||
'author' => object_get($parsed, 'author'),
|
||||
'name' => object_get($parsed, 'name'),
|
||||
'description' => object_get($parsed, 'description'),
|
||||
'features' => object_get($parsed, 'features'),
|
||||
'author' => Arr::get($parsed, 'author'),
|
||||
'name' => Arr::get($parsed, 'name'),
|
||||
'description' => Arr::get($parsed, 'description'),
|
||||
'features' => Arr::get($parsed, 'features'),
|
||||
// Maintain backwards compatability for eggs that are still using the old single image
|
||||
// string format. New eggs can provide an array of Docker images that can be used.
|
||||
'docker_images' => object_get($parsed, 'images') ?? [object_get($parsed, 'image')],
|
||||
'file_denylist' => implode(PHP_EOL, object_get($parsed, 'file_denylist') ?? []),
|
||||
'update_url' => object_get($parsed, 'meta.update_url'),
|
||||
'config_files' => object_get($parsed, 'config.files'),
|
||||
'config_startup' => object_get($parsed, 'config.startup'),
|
||||
'config_logs' => object_get($parsed, 'config.logs'),
|
||||
'config_stop' => object_get($parsed, 'config.stop'),
|
||||
'startup' => object_get($parsed, 'startup'),
|
||||
'script_install' => object_get($parsed, 'scripts.installation.script'),
|
||||
'script_entry' => object_get($parsed, 'scripts.installation.entrypoint'),
|
||||
'script_container' => object_get($parsed, 'scripts.installation.container'),
|
||||
'docker_images' => Arr::get($parsed, 'images') ?? [Arr::get($parsed, 'image')],
|
||||
'file_denylist' => Collection::make(Arr::get($parsed, 'file_denylist'))->filter(function ($value) {
|
||||
return !empty($value);
|
||||
}),
|
||||
'update_url' => Arr::get($parsed, 'meta.update_url'),
|
||||
'config_files' => Arr::get($parsed, 'config.files'),
|
||||
'config_startup' => Arr::get($parsed, 'config.startup'),
|
||||
'config_logs' => Arr::get($parsed, 'config.logs'),
|
||||
'config_stop' => Arr::get($parsed, 'config.stop'),
|
||||
'startup' => Arr::get($parsed, 'startup'),
|
||||
'script_install' => Arr::get($parsed, 'scripts.installation.script'),
|
||||
'script_entry' => Arr::get($parsed, 'scripts.installation.entrypoint'),
|
||||
'script_container' => Arr::get($parsed, 'scripts.installation.container'),
|
||||
'copy_script_from' => null,
|
||||
], true, true);
|
||||
|
||||
collect($parsed->variables)->each(function ($variable) use ($egg) {
|
||||
$this->eggVariableRepository->create(array_merge((array) $variable, [
|
||||
Collection::make($parsed['variables'] ?? [])->each(function (array $variable) use ($egg) {
|
||||
$this->eggVariableRepository->create(array_merge($variable, [
|
||||
'egg_id' => $egg->id,
|
||||
]));
|
||||
});
|
||||
|
|
|
@ -80,7 +80,7 @@ class ServerConfigurationStructureService
|
|||
}),
|
||||
'egg' => [
|
||||
'id' => $server->egg->uuid,
|
||||
'file_denylist' => explode(PHP_EOL, $server->egg->inherit_file_denylist),
|
||||
'file_denylist' => $server->egg->inherit_file_denylist,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -76,8 +76,8 @@ class ServerCreationService
|
|||
* CreationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
||||
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
*/
|
||||
public function __construct(
|
||||
AllocationSelectionService $allocationSelectionService,
|
||||
|
@ -258,7 +258,7 @@ class ServerCreationService
|
|||
return [
|
||||
'server_id' => $server->id,
|
||||
'variable_id' => $result->id,
|
||||
'variable_value' => $result->value,
|
||||
'variable_value' => $result->value ?? '',
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue