Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
Add file contents request
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvan Watchman committed Jun 28, 2019
1 parent 363a273 commit 5737d2c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Controllers/Api/User/FilemanagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace YWatchman\Panel_Console\Controllers\Api\User;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController as Controller;
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use YWatchman\Panel_Console\Requests\ListFilesRequest;
use YWatchman\Panel_Console\Requests\GetFileContentsRequest;
use Pterodactyl\Models\Server;

class FilemanagerController extends Controller
Expand All @@ -32,4 +34,12 @@ public function getDirectoryListing(ListFilesRequest $request) {
]);
}

public function getFileContents(GetFileContentsRequest $request) {
return Response::create(
$this->repository->setServer($request->getModel(Server::class))->getContent(
$request->get('file'), $this->config->get('pterodactyl.files.max_edit_size')
)
);
}

}
15 changes: 15 additions & 0 deletions src/Requests/ClientPermissionsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace YWatchman\Panel_Console\Requests;

interface ClientPermissionsRequest
{
/**
* Returns the permissions string indicating which permission should be used to
* validate that the authenticated user has permission to perform this action aganist
* the given resource (server).
*
* @return string
*/
public function permission(): string;
}
31 changes: 31 additions & 0 deletions src/Requests/GetFileContentsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace YWatchman\Panel_Console\Requests;

use YWatchman\Panel_Console\Requests\ClientPermissionsRequest;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;

class GetFileContentsRequest extends ClientApiRequest implements ClientPermissionsRequest
{
/**
* Returns the permissions string indicating which permission should be used to
* validate that the authenticated user has permission to perform this action aganist
* the given resource (server).
*
* @return string
*/
public function permission(): string
{
return 'edit-files';
}

/**
* @return array
*/
public function rules(): array
{
return [
'file' => 'required|string',
];
}
}
1 change: 1 addition & 0 deletions src/Routes/api-app-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

Route::group(['prefix' => '/files', 'middleware' => [PterodactylAccess::class]], function () {
Route::get('/{server}/list', 'FilemanagerController@getDirectoryListing')->name('api.app.user.files.list');
Route::get('/{server}/content', 'FilemanagerController@getFileContents')->name('api.app.user.files.contents');
});

0 comments on commit 5737d2c

Please sign in to comment.