Skip to content

Commit 0ec5a4e

Browse files
committed
Fix some file management bugs, closes pterodactyl#621
1 parent ffc8d48 commit 0ec5a4e

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

app/Http/Controllers/Server/Files/FileActionsController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ public function create(Request $request): View
9595
* @param string $file
9696
* @return \Illuminate\View\View
9797
*
98-
* @throws \Illuminate\Auth\Access\AuthorizationException
99-
* @throws \Pterodactyl\Exceptions\DisplayException
98+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
10099
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
101100
*/
102-
public function update(UpdateFileContentsFormRequest $request, string $uuid, string $file): View
101+
public function view(UpdateFileContentsFormRequest $request, string $uuid, string $file): View
103102
{
104103
$server = $request->attributes->get('server');
105104

app/Http/Controllers/Server/Files/RemoteRequestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function store(Request $request): Response
101101
$this->repository->setNode($server->node_id)
102102
->setAccessServer($server->uuid)
103103
->setAccessToken($request->attributes->get('server_token'))
104-
->putContent($request->input('file'), $request->input('contents'));
104+
->putContent($request->input('file'), $request->input('contents') ?? '');
105105

106106
return response('', 204);
107107
} catch (RequestException $exception) {

app/Http/Requests/Server/UpdateFileContentsFormRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use GuzzleHttp\Exception\RequestException;
1313
use Illuminate\Contracts\Config\Repository;
1414
use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException;
15+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1516
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
1617
use Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException;
1718
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
@@ -80,7 +81,12 @@ private function checkFileCanBeEdited($server, $token)
8081
->setAccessToken($token)
8182
->getFileStat($this->route()->parameter('file'));
8283
} catch (RequestException $exception) {
83-
throw new DaemonConnectionException($exception);
84+
switch ($exception->getCode()) {
85+
case 404:
86+
throw new NotFoundHttpException;
87+
default:
88+
throw new DaemonConnectionException($exception);
89+
}
8490
}
8591

8692
if (! $stats->file || ! in_array($stats->mime, $config->get('pterodactyl.files.editable'))) {

resources/themes/pterodactyl/server/files/list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
<td data-identifier="name" data-name="{{ rawurlencode($file['entry']) }}" data-path="@if($file['directory'] !== ''){{ rawurlencode($file['directory']) }}@endif/">
138138
@if(in_array($file['mime'], $editableMime))
139139
@can('edit-files', $server)
140-
<a href="/server/{{ $server->uuidShort }}/files/edit/@if($file['directory'] !== ''){{ rawurlencode($file['directory']) }}/@endif{{ rawurlencode($file['entry']) }}" class="edit_file">{{ $file['entry'] }}</a>
140+
<a href="/server/{{ $server->uuidShort }}/files/edit/@if($file['directory'] !== ''){{ $file['directory'] }}/@endif{{ $file['entry'] }}" class="edit_file">{{ $file['entry'] }}</a>
141141
@else
142142
{{ $file['entry'] }}
143143
@endcan

routes/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
Route::group(['prefix' => 'files'], function () {
5353
Route::get('/', 'Files\FileActionsController@index')->name('server.files.index');
5454
Route::get('/add', 'Files\FileActionsController@create')->name('server.files.add');
55-
Route::get('/edit/{file}', 'Files\FileActionsController@update')->name('server.files.edit')->where('file', '.*');
55+
Route::get('/edit/{file}', 'Files\FileActionsController@view')->name('server.files.edit')->where('file', '.*');
5656
Route::get('/download/{file}', 'Files\DownloadController@index')->name('server.files.edit')->where('file', '.*');
5757

5858
Route::post('/directory-list', 'Files\RemoteRequestController@directory')->name('server.files.directory-list');

0 commit comments

Comments
 (0)