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

79 lines
2.6 KiB
PHP
Raw Normal View History

<?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
*/
namespace Pterodactyl\Http\Controllers\Admin\Nests;
use Pterodactyl\Models\Egg;
2017-10-04 04:31:04 +00:00
use Illuminate\Http\RedirectResponse;
use Pterodactyl\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response;
use Pterodactyl\Services\Eggs\Sharing\EggExporterService;
use Pterodactyl\Services\Services\Sharing\EggImporterService;
2017-10-04 04:31:04 +00:00
use Pterodactyl\Http\Requests\Admin\Service\OptionImportFormRequest;
class EggShareController extends Controller
{
/**
* @var \Pterodactyl\Services\Eggs\Sharing\EggExporterService
*/
protected $exporterService;
2017-10-04 04:31:04 +00:00
/**
* @var \Pterodactyl\Services\Services\Sharing\EggImporterService
2017-10-04 04:31:04 +00:00
*/
protected $importerService;
/**
* OptionShareController constructor.
*
* @param \Pterodactyl\Services\Eggs\Sharing\EggExporterService $exporterService
* @param \Pterodactyl\Services\Services\Sharing\EggImporterService $importerService
*/
2017-10-04 04:31:04 +00:00
public function __construct(
EggExporterService $exporterService,
EggImporterService $importerService
2017-10-04 04:31:04 +00:00
) {
$this->exporterService = $exporterService;
2017-10-04 04:31:04 +00:00
$this->importerService = $importerService;
}
/**
* @param \Pterodactyl\Models\Egg $egg
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function export(Egg $egg): Response
{
return response($this->exporterService->handle($egg->id), 200, [
'Content-Transfer-Encoding' => 'binary',
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename=egg-' . kebab_case($egg->name) . '.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.
*
* @param \Pterodactyl\Http\Requests\Admin\Service\OptionImportFormRequest $request
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException
*/
public function import(OptionImportFormRequest $request): RedirectResponse
{
$egg = $this->importerService->handle($request->file('import_file'), $request->input('import_to_nest'));
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
}
}