diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index abb9fcc..cc6f68d 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -572,7 +572,10 @@ class UserController extends Controller $nas->deleteLocalAvatar($user); } - return response()->json(['ok' => true]); + // Return the canonical media URL. The url from image.upload points at the + // temp file we just moved to NAS and deleted, so the client must use this + // instead — otherwise the avatar shows broken until the next page load. + return response()->json(['ok' => true, 'url' => route('media.avatar', $relPath)]); } public function updateBanner(Request $request) @@ -606,6 +609,8 @@ class UserController extends Controller $nas->deleteLocalBanner($user); } - return response()->json(['ok' => true]); + // Return the canonical media URL (see updateAvatar) so the client updates + // the banner in place instead of pointing at the deleted temp file. + return response()->json(['ok' => true, 'url' => route('media.banner', $relPath)]); } } diff --git a/resources/views/components/image-cropper.blade.php b/resources/views/components/image-cropper.blade.php index 399b62b..0b5b3d4 100644 --- a/resources/views/components/image-cropper.blade.php +++ b/resources/views/components/image-cropper.blade.php @@ -234,7 +234,15 @@ method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': getCsrf() }, body: JSON.stringify({ path: res.path }) - }).then(function () { return res; }); + }) + .then(function (r) { return r.json().catch(function () { return {}; }); }) + .then(function (upd) { + // The update step moves the temp upload to its final home (e.g. NAS) + // and deletes the temp, so res.url is now dead. Prefer the canonical + // URL the update endpoint returns; fall back to res.url otherwise. + if (upd && upd.url) res = Object.assign({}, res, { url: upd.url }); + return res; + }); } return res; })