When NAS sync is enabled: - Audio uploads: pushed to NAS via NasSyncVideoJob, local file deleted immediately after - Video uploads: processed locally (ffprobe, compress, HLS), then at the end of GenerateHlsJob the final compressed file is re-synced to NAS and the local copy removed - stream() and download(): if local file is missing, pull from NAS into a local stream cache (storage/app/nas_cache/videos/) and serve from there with full byte-range support — so seeking still works over NAS-sourced files When NAS is disabled: - Upload, stream, and download all use local storage exclusively (no change) HLS segments are intentionally kept local: they are small, generated on-demand, and serving them via per-segment SMB round-trips would hurt playback performance. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Video;
|
|
use App\Services\NasSyncService;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class NasSyncVideoJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 3;
|
|
public int $backoff = 60;
|
|
|
|
public function __construct(public readonly Video $video) {}
|
|
|
|
public function handle(NasSyncService $nas): void
|
|
{
|
|
if (! $nas->isEnabled()) return;
|
|
try {
|
|
$nas->syncVideo($this->video);
|
|
|
|
// Audio/music uploads have no further processing jobs, so it's safe
|
|
// to remove the local file immediately after a successful NAS push.
|
|
// Video uploads must keep the local file until GenerateHlsJob finishes.
|
|
if ($this->video->type === 'music') {
|
|
$nas->deleteLocalVideo($this->video);
|
|
}
|
|
} catch (\Throwable $e) {
|
|
\Illuminate\Support\Facades\Log::warning('NAS syncVideo failed for video ' . $this->video->id . ': ' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|