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
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Services\Options;
|
|
|
|
|
2017-10-04 04:31:04 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-10-03 05:01:04 +00:00
|
|
|
use Pterodactyl\Models\ServiceOption;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-10-04 01:18:27 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2017-10-04 04:31:04 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\Service\OptionImportFormRequest;
|
|
|
|
use Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService;
|
|
|
|
use Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService;
|
2017-10-03 05:01:04 +00:00
|
|
|
|
|
|
|
class OptionShareController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2017-10-04 04:31:04 +00:00
|
|
|
* @var \Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService
|
2017-10-03 05:01:04 +00:00
|
|
|
*/
|
|
|
|
protected $exporterService;
|
|
|
|
|
2017-10-04 04:31:04 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService
|
|
|
|
*/
|
|
|
|
protected $importerService;
|
|
|
|
|
2017-10-03 05:01:04 +00:00
|
|
|
/**
|
|
|
|
* OptionShareController constructor.
|
|
|
|
*
|
2017-10-04 04:31:04 +00:00
|
|
|
* @param \Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService $exporterService
|
|
|
|
* @param \Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService $importerService
|
2017-10-03 05:01:04 +00:00
|
|
|
*/
|
2017-10-04 04:31:04 +00:00
|
|
|
public function __construct(
|
|
|
|
ServiceOptionExporterService $exporterService,
|
|
|
|
ServiceOptionImporterService $importerService
|
|
|
|
) {
|
2017-10-03 05:01:04 +00:00
|
|
|
$this->exporterService = $exporterService;
|
2017-10-04 04:31:04 +00:00
|
|
|
$this->importerService = $importerService;
|
2017-10-03 05:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \Pterodactyl\Models\ServiceOption $option
|
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-04 01:18:27 +00:00
|
|
|
public function export(ServiceOption $option): Response
|
2017-10-03 05:01:04 +00:00
|
|
|
{
|
2017-10-04 01:18:27 +00:00
|
|
|
return response($this->exporterService->handle($option->id), 200, [
|
|
|
|
'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Description' => 'File Transfer',
|
2017-10-04 04:31:04 +00:00
|
|
|
'Content-Disposition' => 'attachment; filename=' . kebab_case($option->name) . '.json',
|
|
|
|
'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.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
{
|
|
|
|
$option = $this->importerService->handle($request->file('import_file'), $request->input('import_to_service'));
|
|
|
|
|
|
|
|
return redirect()->route('admin.services.option.view', ['option' => $option->id]);
|
|
|
|
}
|
2017-10-03 05:01:04 +00:00
|
|
|
}
|