2026-05-15 19:10:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Media\Type as MediaType;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2026-07-25 00:29:41 +00:00
|
|
|
use Illuminate\Validation\Validator;
|
2026-05-15 19:10:21 +00:00
|
|
|
|
|
|
|
|
class StoreUploadRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-15 19:16:42 +00:00
|
|
|
/**
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
*/
|
2026-05-15 19:10:21 +00:00
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$allowed = implode(',', array_merge(
|
|
|
|
|
MediaType::Image->allowedMimeTypes(),
|
|
|
|
|
MediaType::Video->allowedMimeTypes(),
|
feat(linkedin): support PDF document (carousel) posts
Add LinkedIn document posts — the swipeable PDF carousel — for both personal profiles and company pages. This is the format every major competitor exposes via native PDF upload, and the reason a trial user churned.
- New 'document' media type (application/pdf) across the upload pipeline (Type enum, HasMedia, FormRequests incl. chunked, Platform media types)
- New LinkedInDocument / LinkedInPageDocument content types: PDF-only, single-file, with a supportsDocument() flag
- Publisher flow: documents initializeUpload -> PUT -> poll AVAILABLE -> post with content.media.{id,title}; optional document_title meta (falls back to file name)
- PDF is mutually exclusive with image/video, enforced in ContentTypeCompatibleWithMedia
- Frontend: 'Document (PDF)' variant, media rules (100MB cap), composer/gallery/detail PDF cards, real PDF embed in the LinkedIn editor preview, i18n in en/es/pt-BR
- Tests: publishers (personal + page, incl. processing-failure path), enums, compatibility rule, chunked PDF upload, API + MCP document_title round-trip
LinkedIn caps documents at 100MB / 300 pages (Documents API). The page limit is enforced by LinkedIn at publish, not validated client-side.
2026-06-24 19:32:27 +00:00
|
|
|
MediaType::Document->allowedMimeTypes(),
|
2026-05-15 19:10:21 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return [
|
2026-07-25 00:29:41 +00:00
|
|
|
// Largest per-type cap as the FormRequest upper bound; per-type
|
|
|
|
|
// enforcement runs in withValidator() below — same pattern as
|
|
|
|
|
// StoreMediaRequest + PostController::storeMedia.
|
2026-05-15 19:10:21 +00:00
|
|
|
'media' => [
|
|
|
|
|
'required',
|
|
|
|
|
'file',
|
2026-07-25 00:29:41 +00:00
|
|
|
'max:'.MediaType::Video->maxSizeInKb(),
|
2026-05-15 19:10:21 +00:00
|
|
|
"mimetypes:{$allowed}",
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-07-25 00:29:41 +00:00
|
|
|
|
|
|
|
|
public function withValidator(Validator $validator): void
|
|
|
|
|
{
|
|
|
|
|
$validator->after(function (Validator $validator): void {
|
|
|
|
|
$file = $this->file('media');
|
|
|
|
|
|
|
|
|
|
if ($file === null || $validator->errors()->isNotEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$type = MediaType::fromMime((string) $file->getMimeType());
|
|
|
|
|
|
|
|
|
|
if ($type === null) {
|
|
|
|
|
$validator->errors()->add('media', 'This file type is not supported.');
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($file->getSize() > $type->maxSizeInBytes()) {
|
|
|
|
|
$validator->errors()->add(
|
|
|
|
|
'media',
|
|
|
|
|
"File size exceeds the maximum allowed for {$type->value} ({$type->maxSizeInMb()} MB).",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-05-15 19:10:21 +00:00
|
|
|
}
|