More updates to file manager
Not doing individual commits for this, tons of changes for tons of different aspects across multiple files.
This commit is contained in:
parent
fe9c573533
commit
fb4d122a2a
12 changed files with 308 additions and 164 deletions
|
@ -137,7 +137,7 @@ class AjaxController extends Controller
|
|||
'server' => $server,
|
||||
'files' => $directoryContents->files,
|
||||
'folders' => $directoryContents->folders,
|
||||
'extensions' => Repositories\HelperRepository::editableFiles(),
|
||||
'editableMime' => Repositories\HelperRepository::editableFiles(),
|
||||
'directory' => $prevDir
|
||||
]);
|
||||
|
||||
|
|
|
@ -145,9 +145,9 @@ class ServerController extends Controller
|
|||
'server' => $server,
|
||||
'node' => Models\Node::find($server->node),
|
||||
'file' => $file,
|
||||
'contents' => $fileContent->content,
|
||||
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
|
||||
'extension' => $fileInfo->extension
|
||||
'stat' => $fileContent['stat'],
|
||||
'contents' => $fileContent['file']->content,
|
||||
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/'
|
||||
]);
|
||||
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ class FileRepository
|
|||
* Get the contents of a requested file for the server.
|
||||
*
|
||||
* @param string $file
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
public function returnFileContents($file)
|
||||
{
|
||||
|
@ -95,22 +95,39 @@ class FileRepository
|
|||
}
|
||||
|
||||
$file = (object) pathinfo($file);
|
||||
if (!in_array($file->extension, HelperRepository::editableFiles())) {
|
||||
throw new DisplayException('You do not have permission to edit this type of file.');
|
||||
}
|
||||
|
||||
$file->dirname = (in_array($file->dirname, ['.', './', '/'])) ? null : trim($file->dirname, '/') . '/';
|
||||
|
||||
$res = $this->client->request('GET', '/server/file/' . rawurlencode($file->dirname.$file->basename), [
|
||||
$res = $this->client->request('GET', '/server/files/stat/' . rawurlencode($file->dirname.$file->basename) , [
|
||||
'headers' => $this->headers
|
||||
]);
|
||||
|
||||
$stat = json_decode($res->getBody());
|
||||
if($res->getStatusCode() !== 200 || !isset($stat->size)) {
|
||||
throw new DisplayException('The daemon provided a non-200 error code on stat lookup: HTTP\\' . $res->getStatusCode());
|
||||
}
|
||||
|
||||
if (!in_array($stat->mime, HelperRepository::editableFiles())) {
|
||||
throw new DisplayException('You cannot edit that type of file (' . $stat->mime . ') through the panel.');
|
||||
}
|
||||
|
||||
if ($stat->size > 5000000) {
|
||||
throw new DisplayException('That file is too large to open in the browser, consider using a SFTP client.');
|
||||
}
|
||||
|
||||
$res = $this->client->request('GET', '/server/file/' . rawurlencode($file->dirname.$file->basename) , [
|
||||
'headers' => $this->headers
|
||||
]);
|
||||
|
||||
$json = json_decode($res->getBody());
|
||||
if($res->getStatusCode() !== 200 || !isset($json->content)) {
|
||||
throw new DisplayException('Scales provided a non-200 error code: HTTP\\' . $res->getStatusCode());
|
||||
throw new DisplayException('The daemon provided a non-200 error code: HTTP\\' . $res->getStatusCode());
|
||||
}
|
||||
|
||||
return $json;
|
||||
return [
|
||||
'file' => $json,
|
||||
'stat' => $stat
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
@ -130,11 +147,24 @@ class FileRepository
|
|||
|
||||
$file = (object) pathinfo($file);
|
||||
|
||||
if(!in_array($file->extension, HelperRepository::editableFiles())) {
|
||||
throw new DisplayException('You do not have permission to edit this type of file.');
|
||||
$file->dirname = (in_array($file->dirname, ['.', './', '/'])) ? null : trim($file->dirname, '/') . '/';
|
||||
|
||||
$res = $this->client->request('GET', '/server/files/stat/' . rawurlencode($file->dirname.$file->basename) , [
|
||||
'headers' => $this->headers
|
||||
]);
|
||||
|
||||
$stat = json_decode($res->getBody());
|
||||
if($res->getStatusCode() !== 200 || !isset($stat->size)) {
|
||||
throw new DisplayException('The daemon provided a non-200 error code on stat lookup: HTTP\\' . $res->getStatusCode());
|
||||
}
|
||||
|
||||
$file->dirname = (in_array($file->dirname, ['.', './', '/'])) ? null : trim($file->dirname, '/') . '/';
|
||||
if (!in_array($stat->mime, HelperRepository::editableFiles())) {
|
||||
throw new DisplayException('You cannot edit that type of file (' . $stat->mime . ') through the panel.');
|
||||
}
|
||||
|
||||
if ($stat->size > 5000000) {
|
||||
throw new DisplayException('That file is too large to save in the browser, consider using a SFTP client.');
|
||||
}
|
||||
|
||||
$res = $this->client->request('POST', '/server/file/' . rawurlencode($file->dirname.$file->basename), [
|
||||
'headers' => $this->headers,
|
||||
|
|
|
@ -30,25 +30,20 @@ class HelperRepository {
|
|||
* @var array
|
||||
*/
|
||||
protected static $editable = [
|
||||
'txt',
|
||||
'yml',
|
||||
'yaml',
|
||||
'log',
|
||||
'conf',
|
||||
'config',
|
||||
'html',
|
||||
'json',
|
||||
'properties',
|
||||
'props',
|
||||
'cfg',
|
||||
'lang',
|
||||
'ini',
|
||||
'cmd',
|
||||
'sh',
|
||||
'lua',
|
||||
'0' // Supports BungeeCord Files
|
||||
'application/json',
|
||||
'application/javascript',
|
||||
'application/xml',
|
||||
'application/xhtml+xml',
|
||||
'text/xml',
|
||||
'text/css',
|
||||
'text/html',
|
||||
'text/plain',
|
||||
'text/x-perl',
|
||||
'text/x-shellscript',
|
||||
'inode/x-empty'
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue