WIP: storage-fix-local-nas work before playlist controls feature
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
6b3ab5b65e
commit
c160242dbc
46 files changed
+5365
-815
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Playlist;
|
||||
use App\Models\User;
|
||||
use App\Models\Video;
|
||||
use App\Models\VideoSlide;
|
||||
@@ -47,6 +48,11 @@ class MediaController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// Might be a playlist thumbnail
|
||||
if (! file_exists($local)) {
|
||||
$nas->ensureLocalAsset($local, $filename);
|
||||
}
|
||||
|
||||
if (! file_exists($local)) abort(404);
|
||||
}
|
||||
|
||||
@@ -87,6 +93,27 @@ class MediaController extends Controller
|
||||
|
||||
public function avatar(string $filename, NasSyncService $nas): Response
|
||||
{
|
||||
// New format: "users/{slug}/profile/avatar.{ext}"
|
||||
if (str_starts_with($filename, 'users/')) {
|
||||
$local = storage_path('app/' . $filename);
|
||||
|
||||
if (! file_exists($local)) {
|
||||
@mkdir(dirname($local), 0755, true);
|
||||
$user = User::where('avatar', $filename)->first();
|
||||
if ($user) {
|
||||
$dir = "users/{$nas->userSlug($user)}/profile";
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION) ?: 'webp';
|
||||
foreach (["avatar.webp", "avatar.{$ext}"] as $nasFile) {
|
||||
if ($nas->ensureLocalAsset($local, "{$dir}/{$nasFile}")) break;
|
||||
}
|
||||
}
|
||||
if (! file_exists($local)) abort(404);
|
||||
}
|
||||
|
||||
return $this->fileResponse($local);
|
||||
}
|
||||
|
||||
// Legacy flat format
|
||||
$local = storage_path('app/public/avatars/' . $filename);
|
||||
|
||||
if (! file_exists($local)) {
|
||||
@@ -104,6 +131,27 @@ class MediaController extends Controller
|
||||
|
||||
public function banner(string $filename, NasSyncService $nas): Response
|
||||
{
|
||||
// New format: "users/{slug}/profile/cover.{ext}"
|
||||
if (str_starts_with($filename, 'users/')) {
|
||||
$local = storage_path('app/' . $filename);
|
||||
|
||||
if (! file_exists($local)) {
|
||||
@mkdir(dirname($local), 0755, true);
|
||||
$user = User::where('banner', $filename)->first();
|
||||
if ($user) {
|
||||
$dir = "users/{$nas->userSlug($user)}/profile";
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION) ?: 'webp';
|
||||
foreach (["cover.webp", "cover.{$ext}"] as $nasFile) {
|
||||
if ($nas->ensureLocalAsset($local, "{$dir}/{$nasFile}")) break;
|
||||
}
|
||||
}
|
||||
if (! file_exists($local)) abort(404);
|
||||
}
|
||||
|
||||
return $this->fileResponse($local);
|
||||
}
|
||||
|
||||
// Legacy flat format
|
||||
$local = storage_path('app/public/banners/' . $filename);
|
||||
|
||||
if (! file_exists($local)) {
|
||||
@@ -119,6 +167,29 @@ class MediaController extends Controller
|
||||
return $this->fileResponse($local);
|
||||
}
|
||||
|
||||
public function postImage(string $filename, NasSyncService $nas): Response
|
||||
{
|
||||
// New format: "users/{slug}/posts/{id}/{seq}.{ext}"
|
||||
if (str_starts_with($filename, 'users/')) {
|
||||
$local = storage_path('app/' . $filename);
|
||||
|
||||
if (! file_exists($local)) {
|
||||
@mkdir(dirname($local), 0755, true);
|
||||
// NAS path is identical to the relative path stored in DB
|
||||
$nas->ensureLocalAsset($local, $filename);
|
||||
if (! file_exists($local)) abort(404);
|
||||
}
|
||||
|
||||
return $this->fileResponse($local);
|
||||
}
|
||||
|
||||
// Legacy flat format
|
||||
$local = storage_path('app/public/post_images/' . $filename);
|
||||
if (! file_exists($local)) abort(404);
|
||||
|
||||
return $this->fileResponse($local);
|
||||
}
|
||||
|
||||
// ── Helper ────────────────────────────────────────────────────────────────
|
||||
|
||||
private function fileResponse(string $path): Response
|
||||
|
||||
Reference in new issue
Block a user