Skip to content

Commit 92a9146

Browse files
committed
Improve filemanager, get first level folders listing
1 parent 00a3d7d commit 92a9146

File tree

20 files changed

+125
-1318
lines changed

20 files changed

+125
-1318
lines changed

app/Contracts/Repository/Daemon/FileRepositoryInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
1313
* @param string $path
1414
* @return \stdClass
1515
*
16-
* @throws \GuzzleHttp\Exception\RequestException
16+
* @throws \GuzzleHttp\Exception\TransferException
1717
*/
1818
public function getFileStat(string $path): stdClass;
1919

@@ -23,7 +23,7 @@ public function getFileStat(string $path): stdClass;
2323
* @param string $path
2424
* @return string
2525
*
26-
* @throws \GuzzleHttp\Exception\RequestException
26+
* @throws \GuzzleHttp\Exception\TransferException
2727
*/
2828
public function getContent(string $path): string;
2929

@@ -34,7 +34,7 @@ public function getContent(string $path): string;
3434
* @param string $content
3535
* @return \Psr\Http\Message\ResponseInterface
3636
*
37-
* @throws \GuzzleHttp\Exception\RequestException
37+
* @throws \GuzzleHttp\Exception\TransferException
3838
*/
3939
public function putContent(string $path, string $content): ResponseInterface;
4040

@@ -44,7 +44,7 @@ public function putContent(string $path, string $content): ResponseInterface;
4444
* @param string $path
4545
* @return array
4646
*
47-
* @throws \GuzzleHttp\Exception\RequestException
47+
* @throws \GuzzleHttp\Exception\TransferException
4848
*/
4949
public function getDirectory(string $path): array;
5050
}

app/Http/Controllers/Server/ConsoleController.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/Http/Controllers/Server/DatabaseController.php

Lines changed: 0 additions & 165 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Server;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\JsonResponse;
7+
use GuzzleHttp\Exception\TransferException;
8+
use Pterodactyl\Http\Controllers\Controller;
9+
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
10+
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
11+
12+
class FileController extends Controller
13+
{
14+
/**
15+
* @var \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface
16+
*/
17+
private $fileRepository;
18+
19+
/**
20+
* FileController constructor.
21+
*
22+
* @param \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface $fileRepository
23+
*/
24+
public function __construct(FileRepositoryInterface $fileRepository)
25+
{
26+
$this->fileRepository = $fileRepository;
27+
}
28+
29+
/**
30+
* @param \Illuminate\Http\Request $request
31+
* @return \Illuminate\Http\JsonResponse
32+
*
33+
* @throws \Illuminate\Auth\Access\AuthorizationException
34+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
35+
*/
36+
public function index(Request $request): JsonResponse
37+
{
38+
$server = $request->attributes->get('server');
39+
$this->authorize('list-files', $server);
40+
41+
$requestDirectory = '/' . trim(urldecode($request->route()->parameter('directory', '/')), '/');
42+
$directory = [
43+
'header' => $requestDirectory !== '/' ? $requestDirectory : '',
44+
'first' => $requestDirectory !== '/',
45+
];
46+
47+
$goBack = explode('/', trim($requestDirectory, '/'));
48+
if (! empty(array_filter($goBack)) && count($goBack) >= 2) {
49+
array_pop($goBack);
50+
$directory['show'] = true;
51+
$directory['link'] = '/' . implode('/', $goBack);
52+
$directory['link_show'] = implode('/', $goBack) . '/';
53+
}
54+
55+
try {
56+
$contents = $this->fileRepository->setServer($server)->setToken(
57+
$request->attributes->get('server_token')
58+
)->getDirectory($requestDirectory);
59+
} catch (TransferException $exception) {
60+
throw new DaemonConnectionException($exception, true);
61+
}
62+
63+
return JsonResponse::create([
64+
'contents' => $contents,
65+
'editable' => config('pterodactyl.files.editable'),
66+
'current_directory' => $directory,
67+
]);
68+
}
69+
}

0 commit comments

Comments
 (0)