2020-04-04 16:07:09 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-04-04 16:07:09 -07:00
|
|
|
namespace Pterodactyl\Http\Requests\Api\Remote;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Support\JsonValueGuard;
|
|
|
|
|
use UnexpectedValueException;
|
2020-04-04 16:07:09 -07:00
|
|
|
|
|
|
|
|
class ReportBackupCompleteRequest extends FormRequest
|
|
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return ValidationRules
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function rules(): array
|
2020-04-04 16:07:09 -07:00
|
|
|
{
|
|
|
|
|
return [
|
2026-10-05 18:10:18 -04:00
|
|
|
'successful' => ['required', 'boolean'],
|
|
|
|
|
'checksum' => ['nullable', 'string', 'required_if:successful,true'],
|
|
|
|
|
'checksum_type' => ['nullable', 'string', 'required_if:successful,true'],
|
|
|
|
|
'size' => ['nullable', 'numeric', 'required_if:successful,true'],
|
|
|
|
|
'parts' => ['nullable', 'array', 'list'],
|
|
|
|
|
'parts.*.etag' => ['required', 'string'],
|
|
|
|
|
'parts.*.part_number' => ['required', 'integer'],
|
2020-04-04 16:07:09 -07:00
|
|
|
];
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return BackupCompletionData
|
|
|
|
|
*/
|
|
|
|
|
public function payload(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'successful' => $this->boolean('successful'),
|
|
|
|
|
'checksum' => JsonValueGuard::nullableString($this->input('checksum')),
|
|
|
|
|
'checksum_type' => JsonValueGuard::nullableString($this->input('checksum_type')),
|
|
|
|
|
'size' => $this->integer('size'),
|
|
|
|
|
'parts' => $this->parts(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return list<MultipartUploadPart>|null
|
|
|
|
|
*/
|
|
|
|
|
private function parts(): ?array
|
|
|
|
|
{
|
|
|
|
|
$parts = $this->input('parts');
|
|
|
|
|
if ($parts === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw_if(! is_array($parts) || ! array_is_list($parts), UnexpectedValueException::class, 'Multipart upload parts must be a list.');
|
|
|
|
|
|
|
|
|
|
$normalized = [];
|
|
|
|
|
foreach ($parts as $part) {
|
|
|
|
|
throw_unless(is_array($part), UnexpectedValueException::class, 'Each multipart upload part must be a string-keyed array.');
|
|
|
|
|
|
|
|
|
|
$normalized[] = [
|
|
|
|
|
'etag' => JsonValueGuard::string($part['etag'] ?? null),
|
|
|
|
|
'part_number' => JsonValueGuard::integer($part['part_number'] ?? null),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $normalized;
|
|
|
|
|
}
|
2020-04-04 16:07:09 -07:00
|
|
|
}
|