Make NAS the primary storage when enabled (not a mirror)
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 <[email protected]>
This commit is contained in:
1 parent
d1441b213a
commit
0b75acec89
4 files changed
+460
-2
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\CompressVideoJob;
|
||||
use App\Jobs\NasSyncVideoJob;
|
||||
use App\Mail\NewVideoNotification;
|
||||
use App\Mail\VideoUploaded;
|
||||
use App\Notifications\NewVideoUploaded as NewVideoUploadedNotification;
|
||||
@@ -259,6 +260,12 @@ class VideoController extends Controller
|
||||
->onConnection('database');
|
||||
}
|
||||
|
||||
try {
|
||||
NasSyncVideoJob::dispatch($video);
|
||||
} catch (\Throwable $e) {
|
||||
\Illuminate\Support\Facades\Log::warning('NasSyncVideoJob dispatch failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$video->load('user');
|
||||
|
||||
$userEmail = Auth::user()->email;
|
||||
@@ -542,6 +549,12 @@ class VideoController extends Controller
|
||||
|
||||
$video->update($data);
|
||||
|
||||
try {
|
||||
NasSyncVideoJob::dispatch($video->fresh());
|
||||
} catch (\Throwable $e) {
|
||||
\Illuminate\Support\Facades\Log::warning('NasSyncVideoJob dispatch failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
AuditLog::record('video.updated', [
|
||||
'subject_type' => 'Video',
|
||||
'subject_id' => (string) $video->id,
|
||||
@@ -592,6 +605,12 @@ class VideoController extends Controller
|
||||
if ($video->thumbnail) {
|
||||
Storage::delete('public/thumbnails/'.$video->thumbnail);
|
||||
}
|
||||
|
||||
$nasSync = app(\App\Services\NasSyncService::class);
|
||||
if ($nasSync->isEnabled()) {
|
||||
$nasSync->deleteVideo($video);
|
||||
}
|
||||
|
||||
$video->delete();
|
||||
|
||||
if ($request->expectsJson() || $request->ajax()) {
|
||||
@@ -677,8 +696,13 @@ class VideoController extends Controller
|
||||
|
||||
$path = storage_path('app/public/videos/'.$video->filename);
|
||||
|
||||
// If not on local disk, try to pull from NAS (primary storage when NAS is enabled)
|
||||
if (! file_exists($path)) {
|
||||
abort(404, 'Video file not found');
|
||||
$nas = app(\App\Services\NasSyncService::class);
|
||||
$path = $nas->ensureLocalCopy($video);
|
||||
if (! $path) {
|
||||
abort(404, 'Video file not found');
|
||||
}
|
||||
}
|
||||
|
||||
$fileSize = filesize($path);
|
||||
@@ -800,8 +824,13 @@ class VideoController extends Controller
|
||||
|
||||
$path = storage_path('app/public/videos/' . $video->filename);
|
||||
|
||||
// If not on local disk, try to pull from NAS
|
||||
if (! file_exists($path)) {
|
||||
abort(404, 'Video file not found.');
|
||||
$nas = app(\App\Services\NasSyncService::class);
|
||||
$path = $nas->ensureLocalCopy($video);
|
||||
if (! $path) {
|
||||
abort(404, 'Video file not found.');
|
||||
}
|
||||
}
|
||||
|
||||
// Already a video — serve directly, no conversion needed
|
||||
|
||||
Reference in new issue
Block a user