Settings pages: - Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections) - Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal - Add workspace logo upload/delete routes and controller methods - Translate all hardcoded strings in Workspace.vue modals Language system: - Drop languages table, replace language_id FK with locale string column on users - Create config/languages.php for available languages and default locale - Add Spanish (es) translations (13 files) - Simplify HandleInertiaRequests, ProfileController, RegisteredUserController Code quality: - Add declare(strict_types=1) to all PHP files - Fix MastodonPublisher using wrong attribute (filename -> original_filename) - Fix HasMediaTest for new has_photo/photo_url accessors - Fix PublishToSocialPlatformTest type error revealed by strict_types - Remove orphaned Language model from AppServiceProvider morph map - Update User TypeScript interface (has_photo, photo_url, locale) - Eager load media relation on workspaces to prevent N+1 - Add 8 new tests for workspace logo upload/delete - Update workspace settings test to assert members/invitations props All 710 tests passing.
91 lines
2.2 KiB
PHP
91 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\App\Media;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreChunkedMediaRequest extends FormRequest
|
|
{
|
|
private const CONTENT_RANGE_PATTERN = '/bytes (\d+)-(\d+)\/(\d+)/';
|
|
|
|
protected array $allowedModels = [
|
|
'postPlatform',
|
|
'workspace',
|
|
'user',
|
|
];
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'model' => $this->header('X-Model'),
|
|
'model_id' => $this->header('X-Model-Id'),
|
|
'collection' => $this->header('X-Collection', 'default'),
|
|
'file_name' => $this->header('X-File-Name', 'upload'),
|
|
'content_range' => $this->header('Content-Range'),
|
|
]);
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'content_range' => ['required', 'string', 'regex:'.self::CONTENT_RANGE_PATTERN],
|
|
'model' => ['required', 'string', Rule::in($this->allowedModels)],
|
|
'model_id' => ['required', 'string'],
|
|
'collection' => ['sometimes', 'string', 'max:255'],
|
|
'file_name' => ['required', 'string', 'max:255'],
|
|
];
|
|
}
|
|
|
|
public function rangeStart(): int
|
|
{
|
|
return (int) $this->parsedRange()[1];
|
|
}
|
|
|
|
public function rangeEnd(): int
|
|
{
|
|
return (int) $this->parsedRange()[2];
|
|
}
|
|
|
|
public function totalSize(): int
|
|
{
|
|
return (int) $this->parsedRange()[3];
|
|
}
|
|
|
|
public function isLastChunk(): bool
|
|
{
|
|
return ($this->rangeEnd() + 1) >= $this->totalSize();
|
|
}
|
|
|
|
public function isFirstChunk(): bool
|
|
{
|
|
return $this->rangeStart() === 0;
|
|
}
|
|
|
|
public function progress(): int
|
|
{
|
|
return (int) round(($this->rangeEnd() + 1) / $this->totalSize() * 100);
|
|
}
|
|
|
|
public function chunkIdentifier(): string
|
|
{
|
|
return md5($this->input('file_name').$this->totalSize());
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
private function parsedRange(): array
|
|
{
|
|
preg_match(self::CONTENT_RANGE_PATTERN, $this->input('content_range'), $matches);
|
|
|
|
return $matches;
|
|
}
|
|
}
|