2017-10-03 05:01:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Nests;
|
2017-10-03 05:01:04 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
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;
|
2017-10-03 05:01:04 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-10-04 01:18:27 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2017-10-07 04:57:53 +00:00
|
|
|
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;
|
2017-10-09 04:50:52 +00:00
|
|
|
use Pterodactyl\Services\Eggs\Sharing\EggUpdateImporterService;
|
2017-10-03 05:01:04 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
class EggShareController extends Controller
|
2017-10-03 05:01:04 +00:00
|
|
|
{
|
2017-10-09 02:36:22 +00:00
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
2017-10-03 05:01:04 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Services\Eggs\Sharing\EggExporterService
|
2017-10-03 05:01:04 +00:00
|
|
|
*/
|
|
|
|
protected $exporterService;
|
|
|
|
|
2017-10-04 04:31:04 +00:00
|
|
|
/**
|
2017-10-07 21:19:07 +00:00
|
|
|
* @var \Pterodactyl\Services\Eggs\Sharing\EggImporterService
|
2017-10-04 04:31:04 +00:00
|
|
|
*/
|
|
|
|
protected $importerService;
|
|
|
|
|
2017-10-09 04:50:52 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Eggs\Sharing\EggUpdateImporterService
|
|
|
|
*/
|
|
|
|
protected $updateImporterService;
|
|
|
|
|
2017-10-03 05:01:04 +00:00
|
|
|
/**
|
|
|
|
* OptionShareController constructor.
|
|
|
|
*
|
2017-10-09 04:50:52 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Pterodactyl\Services\Eggs\Sharing\EggExporterService $exporterService
|
|
|
|
* @param \Pterodactyl\Services\Eggs\Sharing\EggImporterService $importerService
|
|
|
|
* @param \Pterodactyl\Services\Eggs\Sharing\EggUpdateImporterService $updateImporterService
|
2017-10-03 05:01:04 +00:00
|
|
|
*/
|
2017-10-04 04:31:04 +00:00
|
|
|
public function __construct(
|
2017-10-09 02:36:22 +00:00
|
|
|
AlertsMessageBag $alert,
|
2017-10-07 04:57:53 +00:00
|
|
|
EggExporterService $exporterService,
|
2017-10-09 04:50:52 +00:00
|
|
|
EggImporterService $importerService,
|
|
|
|
EggUpdateImporterService $updateImporterService
|
2017-10-04 04:31:04 +00:00
|
|
|
) {
|
2017-10-09 02:36:22 +00:00
|
|
|
$this->alert = $alert;
|
2017-10-03 05:01:04 +00:00
|
|
|
$this->exporterService = $exporterService;
|
2017-10-04 04:31:04 +00:00
|
|
|
$this->importerService = $importerService;
|
2017-10-09 04:50:52 +00:00
|
|
|
$this->updateImporterService = $updateImporterService;
|
2017-10-03 05:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Models\Egg $egg
|
2017-10-04 01:18:27 +00:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2017-10-03 05:01:04 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function export(Egg $egg): Response
|
2017-10-03 05:01:04 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return response($this->exporterService->handle($egg->id), 200, [
|
2017-10-04 01:18:27 +00:00
|
|
|
'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Description' => 'File Transfer',
|
2017-10-07 04:57:53 +00:00
|
|
|
'Content-Disposition' => 'attachment; filename=egg-' . kebab_case($egg->name) . '.json',
|
2017-10-04 04:31:04 +00:00
|
|
|
'Content-Type' => 'application/json',
|
2017-10-03 05:01:04 +00:00
|
|
|
]);
|
|
|
|
}
|
2017-10-04 04:31:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Import a new service option using an XML file.
|
|
|
|
*
|
2017-10-09 02:36:22 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggImportFormRequest $request
|
2017-10-04 04:31:04 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-10-09 04:50:52 +00:00
|
|
|
* @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
|
|
|
{
|
2017-10-07 04:57:53 +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
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
return redirect()->route('admin.nests.egg.view', ['egg' => $egg->id]);
|
2017-10-04 04:31:04 +00:00
|
|
|
}
|
2017-10-09 04:50:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an existing Egg using a new imported file.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggImportFormRequest $request
|
|
|
|
* @param int $egg
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\BadJsonFormatException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
|
|
|
|
*/
|
|
|
|
public function update(EggImportFormRequest $request, int $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]);
|
|
|
|
}
|
2017-10-03 05:01:04 +00:00
|
|
|
}
|