Finalize service option import/export

This commit is contained in:
Dane Everitt 2017-10-03 23:31:04 -05:00
parent d608c313c3
commit 6269a08db7
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
16 changed files with 405 additions and 271 deletions

View file

@ -9,26 +9,38 @@
namespace Pterodactyl\Http\Controllers\Admin\Services\Options;
use Illuminate\Http\RedirectResponse;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response;
use Pterodactyl\Services\Services\Exporter\XMLExporterService;
use Pterodactyl\Http\Requests\Admin\Service\OptionImportFormRequest;
use Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService;
use Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService;
class OptionShareController extends Controller
{
/**
* @var \Pterodactyl\Services\Services\Exporter\XMLExporterService
* @var \Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService
*/
protected $exporterService;
/**
* @var \Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService
*/
protected $importerService;
/**
* OptionShareController constructor.
*
* @param \Pterodactyl\Services\Services\Exporter\XMLExporterService $exporterService
* @param \Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService $exporterService
* @param \Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService $importerService
*/
public function __construct(XMLExporterService $exporterService)
{
public function __construct(
ServiceOptionExporterService $exporterService,
ServiceOptionImporterService $importerService
) {
$this->exporterService = $exporterService;
$this->importerService = $importerService;
}
/**
@ -42,8 +54,25 @@ class OptionShareController extends Controller
return response($this->exporterService->handle($option->id), 200, [
'Content-Transfer-Encoding' => 'binary',
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename=' . kebab_case($option->name) . '.xml',
'Content-Type' => 'application/xml',
'Content-Disposition' => 'attachment; filename=' . kebab_case($option->name) . '.json',
'Content-Type' => 'application/json',
]);
}
/**
* 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]);
}
}

View file

@ -0,0 +1,26 @@
<?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\Requests\Admin\Service;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class OptionImportFormRequest extends AdminFormRequest
{
/**
* @return array
*/
public function rules(): array
{
return [
'import_file' => 'bail|required|file|max:1000|mimetypes:application/json,text/plain',
'import_to_service' => 'bail|required|integer|exists:services,id',
];
}
}