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) {
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;
}

View file

@ -120,7 +120,12 @@ class AvatarController extends Controller
$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;
}
@ -132,8 +137,8 @@ class AvatarController extends Controller
@unlink(storage_path('app/' . $avatar->thumb_path));
}
$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';
$avatar->change_count = $avatar->change_count + 1;
$avatar->save();

View file

@ -70,7 +70,10 @@ class AvatarOptimize implements ShouldQueue
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;
}
if (is_file($current)) {

View file

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

View file

@ -48,11 +48,17 @@ class AvatarObserver
public function deleting(Avatar $avatar)
{
$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);
}
$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);
}
}

View file

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

View file

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

View file

@ -1,3 +1,4 @@
*
!.gitignore
!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