1 | <?php |
||
12 | class TerminalController extends Controller |
||
13 | { |
||
14 | /** |
||
15 | * $request. |
||
16 | * |
||
17 | * @var \Illuminate\Http\Request |
||
18 | */ |
||
19 | protected $request; |
||
20 | |||
21 | /** |
||
22 | * $responseFactory. |
||
23 | * |
||
24 | * @var \Illuminate\Contracts\Routing\ResponseFactory |
||
25 | */ |
||
26 | protected $responseFactory; |
||
27 | |||
28 | /** |
||
29 | * __construct. |
||
30 | * |
||
31 | * @param \Illuminate\Http\Request $request |
||
32 | * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
||
33 | */ |
||
34 | 2 | public function __construct(Request $request, ResponseFactory $responseFactory) |
|
35 | { |
||
36 | 2 | $this->request = $request; |
|
37 | 2 | $this->responseFactory = $responseFactory; |
|
38 | 2 | } |
|
39 | |||
40 | /** |
||
41 | * index. |
||
42 | * |
||
43 | * @param \Recca0120\Terminal\Kernel $kernel |
||
44 | * @param string $view |
||
45 | * @return \Illuminate\Http\Response |
||
46 | */ |
||
47 | 1 | public function index(Kernel $kernel, $view = 'index') |
|
48 | { |
||
49 | 1 | $kernel->call('list --ansi'); |
|
50 | 1 | $options = json_encode(array_merge($kernel->getConfig(), [ |
|
51 | 1 | 'helpInfo' => $kernel->output(), |
|
52 | 1 | ])); |
|
53 | 1 | $id = ($view === 'panel') ? Str::random(30) : null; |
|
54 | |||
55 | 1 | return $this->responseFactory->view('terminal::'.$view, compact('options', 'id')); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * rpc response. |
||
60 | * |
||
61 | * @param \Recca0120\Terminal\Kernel $kernel |
||
62 | * @return \Illuminate\Http\JsonResponse |
||
63 | */ |
||
64 | 1 | public function endpoint(Kernel $kernel) |
|
65 | { |
||
66 | 1 | $error = $kernel->call($this->request->get('command')); |
|
67 | |||
68 | 1 | return $this->responseFactory->json([ |
|
69 | 1 | 'jsonrpc' => $this->request->get('jsonrpc'), |
|
70 | 1 | 'id' => $this->request->get('id'), |
|
71 | 1 | 'result' => $kernel->output(), |
|
72 | 1 | 'error' => $error, |
|
73 | 1 | ]); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * media. |
||
78 | * |
||
79 | * @param \Illuminate\Filesystem\Filesystem $files |
||
80 | * @param string $file |
||
81 | * @return \Illuminate\Http\Response |
||
82 | */ |
||
83 | public function media(Filesystem $files, $file) |
||
110 | } |
||
111 |