Merge branch 'develop' into matthewpi/transfer-improvements
This commit is contained in:
commit
6fa24d4979
49 changed files with 88 additions and 4473 deletions
|
@ -25,11 +25,13 @@ class Kernel extends ConsoleKernel
|
|||
// Execute scheduled commands for servers every minute, as if there was a normal cron running.
|
||||
$schedule->command('p:schedule:process')->everyMinute()->withoutOverlapping();
|
||||
|
||||
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be removed
|
||||
// from the UI view for the server.
|
||||
$schedule->command('p:maintenance:prune-backups', [
|
||||
'--since-minutes' => '30',
|
||||
])->everyThirtyMinutes();
|
||||
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted.
|
||||
$pruneAge = config('backups.prune_age', 360); // Defaults to 6 hours (time is in minuteS)
|
||||
if ($pruneAge > 0) {
|
||||
$schedule->command('p:maintenance:prune-backups', [
|
||||
'--since-minutes' => $pruneAge,
|
||||
])->everyThirtyMinutes();
|
||||
}
|
||||
|
||||
// Every day cleanup any internal backups of service files.
|
||||
$schedule->command('p:maintenance:clean-service-backups')->daily();
|
||||
|
|
|
@ -13,6 +13,7 @@ use Pterodactyl\Repositories\Wings\DaemonFileRepository;
|
|||
use Pterodactyl\Transformers\Daemon\FileObjectTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CopyFileRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\PullFileRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DeleteFileRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest;
|
||||
|
@ -143,10 +144,7 @@ class FileController extends ClientApiController
|
|||
*/
|
||||
public function write(WriteFileContentRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
$this->fileRepository->setServer($server)->putContent(
|
||||
$this->encode($request->get('file')),
|
||||
$request->getContent()
|
||||
);
|
||||
$this->fileRepository->setServer($server)->putContent($request->get('file'), $request->getContent());
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
@ -284,16 +282,18 @@ class FileController extends ClientApiController
|
|||
}
|
||||
|
||||
/**
|
||||
* Encodes a given file name & path in a format that should work for a good majority
|
||||
* of file names without too much confusing logic.
|
||||
* Requests that a file be downloaded from a remote location by Wings.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
* @param $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
private function encode(string $path): string
|
||||
public function pull(PullFileRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
return Collection::make(explode('/', rawurldecode($path)))->map(function ($value) {
|
||||
return rawurlencode($value);
|
||||
})->join('/');
|
||||
$this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory'));
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class BackupRemoteUploadController extends Controller
|
|||
public function __invoke(Request $request, string $backup)
|
||||
{
|
||||
// Get the size query parameter.
|
||||
$size = (int)$request->query('size');
|
||||
$size = (int) $request->query('size');
|
||||
if (empty($size)) {
|
||||
throw new BadRequestHttpException('A non-empty "size" query parameter must be provided.');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Files;
|
||||
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
|
||||
class PullFileRequest extends ClientApiRequest implements ClientPermissionsRequest
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function permission(): string
|
||||
{
|
||||
return Permission::ACTION_FILE_CREATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'url' => 'required|string|url',
|
||||
'directory' => 'sometimes|nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Wings;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
@ -48,7 +49,7 @@ class DaemonBackupRepository extends DaemonRepository
|
|||
'json' => [
|
||||
'adapter' => $this->adapter ?? config('backups.default'),
|
||||
'uuid' => $backup->uuid,
|
||||
'ignored_files' => $backup->ignored_files,
|
||||
'ignore' => implode('\n', $backup->ignored_files),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
|
|
@ -37,7 +37,7 @@ class DaemonFileRepository extends DaemonRepository
|
|||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
|
||||
$length = (int) $response->getHeader('Content-Length')[0] ?? 0;
|
||||
$length = (int)$response->getHeader('Content-Length')[0] ?? 0;
|
||||
|
||||
if ($notLargerThan && $length > $notLargerThan) {
|
||||
throw new FileSizeTooLargeException;
|
||||
|
@ -297,4 +297,29 @@ class DaemonFileRepository extends DaemonRepository
|
|||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls a file from the given URL and saves it to the disk.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string|null $directory
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function pull(string $url, ?string $directory): ResponseInterface
|
||||
{
|
||||
Assert::isInstanceOf($this->server, Server::class);
|
||||
|
||||
try {
|
||||
return $this->getHttpClient()->post(
|
||||
sprintf('/api/servers/%s/files/pull', $this->server->uuid),
|
||||
[
|
||||
'json' => ['url' => $url, 'directory' => $directory ?? '/'],
|
||||
]
|
||||
);
|
||||
} catch (TransferException $exception) {
|
||||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,9 +117,9 @@ class InitiateBackupService
|
|||
}
|
||||
|
||||
// Check if the server has reached or exceeded it's backup limit
|
||||
if (!$server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) {
|
||||
if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) {
|
||||
// Do not allow the user to continue if this server is already at its limit and can't override.
|
||||
if (!$override || $server->backup_limit <= 0) {
|
||||
if (! $override || $server->backup_limit <= 0) {
|
||||
throw new TooManyBackupsException($server->backup_limit);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue