Update avatars, use jpeg default

This commit is contained in:
Daniel Supernault 2020-12-14 23:54:22 -07:00
parent d698b4d1d2
commit f6528c8470
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
10 changed files with 31 additions and 10 deletions

View File

@ -53,7 +53,11 @@ class AvatarDefaultMigration extends Command
Avatar::whereChangeCount(0)->chunk(50, function($avatars) use ($bar) { Avatar::whereChangeCount(0)->chunk(50, function($avatars) use ($bar) {
foreach($avatars as $avatar) { foreach($avatars as $avatar) {
if($avatar->media_path == 'public/avatars/default.png' || $avatar->thumb_path == 'public/avatars/default.png') { if( $avatar->media_path == 'public/avatars/default.png' ||
$avatar->thumb_path == 'public/avatars/default.png' ||
$avatar->media_path == 'public/avatars/default.jpg' ||
$avatar->thumb_path == 'public/avatars/default.jpg' ||
) {
continue; continue;
} }

View File

@ -120,7 +120,12 @@ class AvatarController extends Controller
$avatar = $profile->avatar; $avatar = $profile->avatar;
if($avatar->media_path == 'public/avatars/default.png' || $avatar->thumb_path == 'public/avatars/default.png') { if( $avatar->media_path == 'public/avatars/default.png' ||
$avatar->thumb_path == 'public/avatars/default.png' ||
$avatar->media_path == 'public/avatars/default.jpg' ||
$avatar->thumb_path == 'public/avatars/default.jpg' ||
) {
return; return;
} }
@ -132,8 +137,8 @@ class AvatarController extends Controller
@unlink(storage_path('app/' . $avatar->thumb_path)); @unlink(storage_path('app/' . $avatar->thumb_path));
} }
$avatar->media_path = 'public/avatars/default.png'; $avatar->media_path = 'public/avatars/default.jpg';
$avatar->thumb_path = 'public/avatars/default.png'; $avatar->thumb_path = 'public/avatars/default.jpg';
$avatar->change_count = $avatar->change_count + 1; $avatar->change_count = $avatar->change_count + 1;
$avatar->save(); $avatar->save();

View File

@ -70,7 +70,10 @@ class AvatarOptimize implements ShouldQueue
protected function deleteOldAvatar($new, $current) protected function deleteOldAvatar($new, $current)
{ {
if (storage_path('app/'.$new) == $current || Str::endsWith($current, 'avatars/default.png')) { if ( storage_path('app/'.$new) == $current ||
Str::endsWith($current, 'avatars/default.png') ||
Str::endsWith($current, 'avatars/default.jpg'))
{
return; return;
} }
if (is_file($current)) { if (is_file($current)) {

View File

@ -41,7 +41,7 @@ class CreateAvatar implements ShouldQueue
public function handle() public function handle()
{ {
$profile = $this->profile; $profile = $this->profile;
$path = 'public/avatars/default.png'; $path = 'public/avatars/default.jpg';
$avatar = new Avatar(); $avatar = new Avatar();
$avatar->profile_id = $profile->id; $avatar->profile_id = $profile->id;
$avatar->media_path = $path; $avatar->media_path = $path;

View File

@ -48,11 +48,17 @@ class AvatarObserver
public function deleting(Avatar $avatar) public function deleting(Avatar $avatar)
{ {
$path = storage_path('app/'.$avatar->media_path); $path = storage_path('app/'.$avatar->media_path);
if(is_file($path) && $avatar->media_path != 'public/avatars/default.png') { if( is_file($path) &&
$avatar->media_path != 'public/avatars/default.png' &&
$avatar->media_path != 'public/avatars/default.jpg'
) {
@unlink($path); @unlink($path);
} }
$path = storage_path('app/'.$avatar->thumb_path); $path = storage_path('app/'.$avatar->thumb_path);
if(is_file($path) && $avatar->thumb_path != 'public/avatars/default.png') { if( is_file($path) &&
$avatar->thumb_path != 'public/avatars/default.png' &&
$avatar->media_path != 'public/avatars/default.jpg'
) {
@unlink($path); @unlink($path);
} }
} }

View File

@ -156,7 +156,7 @@ class Profile extends Model
public function avatar() public function avatar()
{ {
return $this->hasOne(Avatar::class)->withDefault([ return $this->hasOne(Avatar::class)->withDefault([
'media_path' => 'public/avatars/default.png', 'media_path' => 'public/avatars/default.jpg',
'change_count' => 0 'change_count' => 0
]); ]);
} }

View File

@ -103,6 +103,8 @@ class RestrictedNames
'api', 'api',
'audio', 'audio',
'auth', 'auth',
'avatar',
'avatars',
'b', 'b',
'bartender', 'bartender',
'broadcast', 'broadcast',

View File

@ -1,3 +1,4 @@
* *
!.gitignore !.gitignore
!default.png !default.png
!default.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 14 KiB