mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 08:13:16 +00:00
Update AvatarController
This commit is contained in:
parent
acd705e9d3
commit
b7547a4ad4
1 changed files with 29 additions and 0 deletions
|
@ -96,4 +96,33 @@ class AvatarController extends Controller
|
|||
|
||||
return $avatarpath;
|
||||
}
|
||||
|
||||
public function deleteAvatar(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
|
||||
$avatar = $profile->avatar;
|
||||
|
||||
if($avatar->media_path == 'public/avatars/default.png' || $avatar->thumb_path == 'public/avatars/default.png') {
|
||||
return;
|
||||
}
|
||||
|
||||
if(is_file(storage_path('app/' . $avatar->media_path))) {
|
||||
@unlink(storage_path('app/' . $avatar->media_path));
|
||||
}
|
||||
|
||||
if(is_file(storage_path('app/' . $avatar->thumb_path))) {
|
||||
@unlink(storage_path('app/' . $avatar->thumb_path));
|
||||
}
|
||||
|
||||
$avatar->media_path = 'public/avatars/default.png';
|
||||
$avatar->thumb_path = 'public/avatars/default.png';
|
||||
$avatar->change_count = $avatar->change_count + 1;
|
||||
$avatar->save();
|
||||
|
||||
Cache::forget('avatar:' . $avatar->profile_id);
|
||||
|
||||
return response()->json(200);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue