misc_pterodactyl-panel/app/Http/Controllers/Admin/Nests/EggShareController.php

75 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Http\Controllers\Admin\Nests;
use Pterodactyl\Models\Egg;
2017-10-04 04:31:04 +00:00
use Illuminate\Http\RedirectResponse;
2017-10-09 02:36:22 +00:00
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response;
use Pterodactyl\Services\Eggs\Sharing\EggExporterService;
2017-10-07 21:19:07 +00:00
use Pterodactyl\Services\Eggs\Sharing\EggImporterService;
2017-10-09 02:36:22 +00:00
use Pterodactyl\Http\Requests\Admin\Egg\EggImportFormRequest;
use Pterodactyl\Services\Eggs\Sharing\EggUpdateImporterService;
class EggShareController extends Controller
{
2017-10-09 02:36:22 +00:00
/**
* EggShareController constructor.
*/
2017-10-04 04:31:04 +00:00
public function __construct(
protected AlertsMessageBag $alert,
protected EggExporterService $exporterService,
protected EggImporterService $importerService,
protected EggUpdateImporterService $updateImporterService
2017-10-04 04:31:04 +00:00
) {
}
/**
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function export(Egg $egg): Response
{
$filename = trim(preg_replace('/\W/', '-', kebab_case($egg->name)), '-');
2017-11-04 04:07:18 +00:00
return response($this->exporterService->handle($egg->id), 200, [
'Content-Transfer-Encoding' => 'binary',
'Content-Description' => 'File Transfer',
2017-11-04 04:07:18 +00:00
'Content-Disposition' => 'attachment; filename=egg-' . $filename . '.json',
2017-10-04 04:31:04 +00:00
'Content-Type' => 'application/json',
]);
}
2017-10-04 04:31:04 +00:00
/**
* Import a new service option using an XML file.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\BadJsonFormatException
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
2017-10-04 04:31:04 +00:00
*/
2017-10-09 02:36:22 +00:00
public function import(EggImportFormRequest $request): RedirectResponse
2017-10-04 04:31:04 +00:00
{
$egg = $this->importerService->handle($request->file('import_file'), $request->input('import_to_nest'));
2017-10-09 02:36:22 +00:00
$this->alert->success(trans('admin/nests.eggs.notices.imported'))->flash();
2017-10-04 04:31:04 +00:00
return redirect()->route('admin.nests.egg.view', ['egg' => $egg->id]);
2017-10-04 04:31:04 +00:00
}
/**
* Update an existing Egg using a new imported file.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\BadJsonFormatException
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
*/
2020-10-06 04:29:35 +00:00
public function update(EggImportFormRequest $request, Egg $egg): RedirectResponse
{
$this->updateImporterService->handle($egg, $request->file('import_file'));
$this->alert->success(trans('admin/nests.eggs.notices.updated_via_import'))->flash();
return redirect()->route('admin.nests.egg.view', ['egg' => $egg]);
}
}