2017-10-07 04:57:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Eggs\Sharing;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2021-01-27 05:08:53 +00:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Pterodactyl\Models\EggVariable;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
|
|
|
|
|
|
|
class EggExporterService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EggExporterService constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(EggRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a JSON representation of an egg and its variables.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function handle(int $egg): string
|
|
|
|
{
|
|
|
|
$egg = $this->repository->getWithExportAttributes($egg);
|
|
|
|
|
|
|
|
$struct = [
|
|
|
|
'_comment' => 'DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO',
|
|
|
|
'meta' => [
|
|
|
|
'version' => 'PTDL_v1',
|
2020-12-13 17:53:17 +00:00
|
|
|
'update_url' => $egg->update_url,
|
2017-10-07 04:57:53 +00:00
|
|
|
],
|
|
|
|
'exported_at' => Carbon::now()->toIso8601String(),
|
|
|
|
'name' => $egg->name,
|
|
|
|
'author' => $egg->author,
|
|
|
|
'description' => $egg->description,
|
2020-11-03 04:20:36 +00:00
|
|
|
'features' => $egg->features,
|
2020-12-13 17:53:17 +00:00
|
|
|
'images' => $egg->docker_images,
|
2021-01-27 05:08:53 +00:00
|
|
|
'file_denylist' => Collection::make($egg->inherit_file_denylist)->filter(function ($value) {
|
|
|
|
return !empty($value);
|
|
|
|
}),
|
2017-10-09 02:36:22 +00:00
|
|
|
'startup' => $egg->startup,
|
2017-10-07 04:57:53 +00:00
|
|
|
'config' => [
|
|
|
|
'files' => $egg->inherit_config_files,
|
|
|
|
'startup' => $egg->inherit_config_startup,
|
|
|
|
'logs' => $egg->inherit_config_logs,
|
|
|
|
'stop' => $egg->inherit_config_stop,
|
|
|
|
],
|
|
|
|
'scripts' => [
|
|
|
|
'installation' => [
|
|
|
|
'script' => $egg->copy_script_install,
|
|
|
|
'container' => $egg->copy_script_container,
|
|
|
|
'entrypoint' => $egg->copy_script_entry,
|
|
|
|
],
|
|
|
|
],
|
2021-01-27 05:08:53 +00:00
|
|
|
'variables' => $egg->variables->transform(function (EggVariable $item) {
|
|
|
|
return Collection::make($item->toArray())
|
|
|
|
->except(['id', 'egg_id', 'created_at', 'updated_at'])
|
|
|
|
->toArray();
|
2017-10-07 04:57:53 +00:00
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
return json_encode($struct, JSON_PRETTY_PRINT);
|
|
|
|
}
|
|
|
|
}
|