WIP: storage-fix-local-nas work before playlist controls feature

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
ghassanandClaude Sonnet 4.6 committed 2026-05-16 11:15:20 +03:00
1 parent 6b3ab5b65e
commit c160242dbc
46 files changed
+5365 -815

No files matched your search

+81 -8
View File
@@ -68,17 +68,36 @@ class UserController extends Controller
'timezone' => $request->timezone ?: null,
];
$nas = app(\App\Services\NasSyncService::class);
if ($request->hasFile('avatar')) {
if ($user->avatar) {
Storage::delete('public/avatars/'.$user->avatar);
}
$filename = self::generateFilename($request->file('avatar')->getClientOriginalExtension());
$request->file('avatar')->storeAs('public/avatars', $filename);
$data['avatar'] = $filename;
// Delete old avatar (handles both flat and new relative-path formats)
$nas->deleteLocalAvatar($user);
$ext = $request->file('avatar')->getClientOriginalExtension() ?: 'webp';
$profileDir = $nas->localProfileDir($user);
$destFilename = "avatar.{$ext}";
$destPath = "{$profileDir}/{$destFilename}";
$relPath = 'users/' . $nas->userSlug($user) . "/profile/{$destFilename}";
@mkdir($profileDir, 0755, true);
$request->file('avatar')->move($profileDir, $destFilename);
$data['avatar'] = $relPath;
}
$user->update($data);
// Push avatar to NAS and remove local copy when NAS is primary storage
if ($nas->isEnabled()) {
if ($request->hasFile('avatar')) {
$destPath = storage_path('app/' . $data['avatar']);
if (file_exists($destPath)) {
$nas->syncAvatar($user, $destPath);
$nas->deleteLocalAvatar($user);
}
}
}
// Sync social links
$user->socialLinks()->delete();
$order = 0;
@@ -418,14 +437,68 @@ class UserController extends Controller
public function updateAvatar(Request $request)
{
$request->validate(['path' => 'required|string|max:300']);
Auth::user()->update(['avatar' => basename($request->path)]);
$user = Auth::user();
$filename = basename($request->path);
$tempPath = storage_path('app/public/avatars/' . $filename);
$nas = app(\App\Services\NasSyncService::class);
// Move temp file into the user's profile directory
$profileDir = $nas->localProfileDir($user);
$ext = pathinfo($filename, PATHINFO_EXTENSION) ?: 'webp';
$destFilename = "avatar.{$ext}";
$destPath = "{$profileDir}/{$destFilename}";
$relPath = 'users/' . $nas->userSlug($user) . "/profile/{$destFilename}";
// Delete old avatar before moving new one in (handles both path formats)
$nas->deleteLocalAvatar($user);
@mkdir($profileDir, 0755, true);
if (file_exists($tempPath)) {
rename($tempPath, $destPath);
}
$user->update(['avatar' => $relPath]);
if ($nas->isEnabled() && file_exists($destPath)) {
$nas->syncAvatar($user, $destPath);
$nas->deleteLocalAvatar($user);
}
return response()->json(['ok' => true]);
}
public function updateBanner(Request $request)
{
$request->validate(['path' => 'required|string|max:300']);
Auth::user()->update(['banner' => basename($request->path)]);
$user = Auth::user();
$filename = basename($request->path);
$tempPath = storage_path('app/public/banners/' . $filename);
$nas = app(\App\Services\NasSyncService::class);
// Move temp file into the user's profile directory
$profileDir = $nas->localProfileDir($user);
$ext = pathinfo($filename, PATHINFO_EXTENSION) ?: 'webp';
$destFilename = "cover.{$ext}";
$destPath = "{$profileDir}/{$destFilename}";
$relPath = 'users/' . $nas->userSlug($user) . "/profile/{$destFilename}";
// Delete old banner before moving new one in (handles both path formats)
$nas->deleteLocalBanner($user);
@mkdir($profileDir, 0755, true);
if (file_exists($tempPath)) {
rename($tempPath, $destPath);
}
$user->update(['banner' => $relPath]);
if ($nas->isEnabled() && file_exists($destPath)) {
$nas->syncCover($user, $destPath);
$nas->deleteLocalBanner($user);
}
return response()->json(['ok' => true]);
}
}