2026-01-15 01:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
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.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Enums\Media\Type as MediaType;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Database\Factories\MediaFactory;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-01-17 17:44:37 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
2026-01-17 17:44:37 +00:00
|
|
|
class Media extends Model
|
2026-01-15 01:13:44 +00:00
|
|
|
{
|
2026-03-29 22:24:28 +00:00
|
|
|
/** @use HasFactory<MediaFactory> */
|
2026-01-15 01:13:44 +00:00
|
|
|
use HasFactory, HasUuids;
|
|
|
|
|
|
2026-01-17 17:44:37 +00:00
|
|
|
protected $table = 'medias';
|
2026-01-17 02:46:30 +00:00
|
|
|
|
2026-01-15 17:24:39 +00:00
|
|
|
protected $appends = ['url'];
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
protected $fillable = [
|
2026-01-17 17:44:37 +00:00
|
|
|
'mediable_id',
|
|
|
|
|
'mediable_type',
|
2026-01-21 20:57:15 +00:00
|
|
|
'group_id',
|
2026-01-17 17:44:37 +00:00
|
|
|
'collection',
|
2026-01-15 01:13:44 +00:00
|
|
|
'type',
|
|
|
|
|
'path',
|
|
|
|
|
'original_filename',
|
|
|
|
|
'mime_type',
|
|
|
|
|
'size',
|
|
|
|
|
'order',
|
|
|
|
|
'meta',
|
2026-05-15 19:02:46 +00:00
|
|
|
'upload_token',
|
2026-01-15 01:13:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'type' => MediaType::class,
|
|
|
|
|
'size' => 'integer',
|
|
|
|
|
'order' => 'integer',
|
|
|
|
|
'meta' => 'array',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 17:44:37 +00:00
|
|
|
public function mediable(): MorphTo
|
2026-01-15 01:13:44 +00:00
|
|
|
{
|
2026-01-17 17:44:37 +00:00
|
|
|
return $this->morphTo();
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function url(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
2026-01-15 17:24:39 +00:00
|
|
|
get: fn () => Storage::url($this->path),
|
2026-01-15 01:13:44 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
fix: overhaul social publishing — validation, uploads, token refresh
- Fix UpdatePostRequest missing content_type, synced, meta fields
(content_type was silently dropped, causing Instagram Reels to post as Feed)
- Create API FormRequests (StorePostRequest, UpdatePostRequest) replacing inline validation
- Fix syntax errors in all publishers ($media->isVideo() missing variable)
- Fix Instagram Feed with single video calling publishSingleImage instead of publishReel
- Fix TikTok hardcoded SELF_ONLY privacy — now queries creator_info API
- Refactor YouTubePublisher to use google/apiclient SDK with chunked resumable upload
- Fix all publishers using file_get_contents for large videos (memory overflow)
— X, LinkedIn, LinkedInPage, Pinterest, Bluesky, Mastodon now use temp file + stream
- Fix Media::isVideo/isImage to use mime_type instead of extension
- Fix Threads not saving refresh_token (was null, now saves access_token)
- Add Instagram token refresh to publisher and ConnectionVerifier
- Fix PublishToSocialPlatform job: tries 3→1 (prevents duplicate uploads),
timeout 60→600s, added failed() method for cleanup
- Increase Horizon worker timeout 60→630s, Redis retry_after 90→660s
- Increase upload limit 500MB→1GB
- Add mastodon to getDefaultContentType in Edit.vue
2026-03-31 22:25:19 +00:00
|
|
|
public function isVideo(): bool
|
|
|
|
|
{
|
2026-06-25 13:57:57 +00:00
|
|
|
return MediaType::classify($this->mime_type, $this->path) === MediaType::Video;
|
fix: overhaul social publishing — validation, uploads, token refresh
- Fix UpdatePostRequest missing content_type, synced, meta fields
(content_type was silently dropped, causing Instagram Reels to post as Feed)
- Create API FormRequests (StorePostRequest, UpdatePostRequest) replacing inline validation
- Fix syntax errors in all publishers ($media->isVideo() missing variable)
- Fix Instagram Feed with single video calling publishSingleImage instead of publishReel
- Fix TikTok hardcoded SELF_ONLY privacy — now queries creator_info API
- Refactor YouTubePublisher to use google/apiclient SDK with chunked resumable upload
- Fix all publishers using file_get_contents for large videos (memory overflow)
— X, LinkedIn, LinkedInPage, Pinterest, Bluesky, Mastodon now use temp file + stream
- Fix Media::isVideo/isImage to use mime_type instead of extension
- Fix Threads not saving refresh_token (was null, now saves access_token)
- Add Instagram token refresh to publisher and ConnectionVerifier
- Fix PublishToSocialPlatform job: tries 3→1 (prevents duplicate uploads),
timeout 60→600s, added failed() method for cleanup
- Increase Horizon worker timeout 60→630s, Redis retry_after 90→660s
- Increase upload limit 500MB→1GB
- Add mastodon to getDefaultContentType in Edit.vue
2026-03-31 22:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isImage(): bool
|
|
|
|
|
{
|
2026-06-25 13:57:57 +00:00
|
|
|
return MediaType::classify($this->mime_type, $this->path) === MediaType::Image;
|
fix: overhaul social publishing — validation, uploads, token refresh
- Fix UpdatePostRequest missing content_type, synced, meta fields
(content_type was silently dropped, causing Instagram Reels to post as Feed)
- Create API FormRequests (StorePostRequest, UpdatePostRequest) replacing inline validation
- Fix syntax errors in all publishers ($media->isVideo() missing variable)
- Fix Instagram Feed with single video calling publishSingleImage instead of publishReel
- Fix TikTok hardcoded SELF_ONLY privacy — now queries creator_info API
- Refactor YouTubePublisher to use google/apiclient SDK with chunked resumable upload
- Fix all publishers using file_get_contents for large videos (memory overflow)
— X, LinkedIn, LinkedInPage, Pinterest, Bluesky, Mastodon now use temp file + stream
- Fix Media::isVideo/isImage to use mime_type instead of extension
- Fix Threads not saving refresh_token (was null, now saves access_token)
- Add Instagram token refresh to publisher and ConnectionVerifier
- Fix PublishToSocialPlatform job: tries 3→1 (prevents duplicate uploads),
timeout 60→600s, added failed() method for cleanup
- Increase Horizon worker timeout 60→630s, Redis retry_after 90→660s
- Increase upload limit 500MB→1GB
- Add mastodon to getDefaultContentType in Edit.vue
2026-03-31 22:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
public function isDocument(): bool
|
|
|
|
|
{
|
2026-06-25 13:57:57 +00:00
|
|
|
return MediaType::classify($this->mime_type, $this->path) === MediaType::Document;
|
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
|
|
|
}
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
public function getTemporaryUrl(int $expirationMinutes = 60): string
|
|
|
|
|
{
|
2026-01-15 17:24:39 +00:00
|
|
|
return Storage::temporaryUrl(
|
2026-01-15 01:13:44 +00:00
|
|
|
$this->path,
|
|
|
|
|
now()->addMinutes($expirationMinutes)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function delete(): bool
|
|
|
|
|
{
|
2026-01-21 20:57:15 +00:00
|
|
|
// Only delete the file if no other media records use the same path
|
|
|
|
|
$otherMediaWithSamePath = static::where('path', $this->path)
|
|
|
|
|
->where('id', '!=', $this->id)
|
|
|
|
|
->exists();
|
|
|
|
|
|
|
|
|
|
if (! $otherMediaWithSamePath) {
|
|
|
|
|
Storage::delete($this->path);
|
|
|
|
|
}
|
2026-01-15 01:13:44 +00:00
|
|
|
|
|
|
|
|
return parent::delete();
|
|
|
|
|
}
|
|
|
|
|
}
|