forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionShareController.php
More file actions
78 lines (70 loc) · 2.79 KB
/
OptionShareController.php
File metadata and controls
78 lines (70 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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;
use Illuminate\Http\RedirectResponse;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response;
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\Sharing\ServiceOptionExporterService
*/
protected $exporterService;
/**
* @var \Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService
*/
protected $importerService;
/**
* OptionShareController constructor.
*
* @param \Pterodactyl\Services\Services\Sharing\ServiceOptionExporterService $exporterService
* @param \Pterodactyl\Services\Services\Sharing\ServiceOptionImporterService $importerService
*/
public function __construct(
ServiceOptionExporterService $exporterService,
ServiceOptionImporterService $importerService
) {
$this->exporterService = $exporterService;
$this->importerService = $importerService;
}
/**
* @param \Pterodactyl\Models\ServiceOption $option
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function export(ServiceOption $option): Response
{
return response($this->exporterService->handle($option->id), 200, [
'Content-Transfer-Encoding' => 'binary',
'Content-Description' => 'File Transfer',
'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]);
}
}