Skip to content

Commit

Permalink
Update avatars, use jpeg default
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Dec 15, 2020
1 parent d698b4d commit f6528c8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 10 deletions.
6 changes: 5 additions & 1 deletion app/Console/Commands/AvatarDefaultMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public function handle()

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

Expand Down
11 changes: 8 additions & 3 deletions app/Http/Controllers/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ public function deleteAvatar(Request $request)

$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;
}

Expand All @@ -132,8 +137,8 @@ public function deleteAvatar(Request $request)
@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();

Expand Down
5 changes: 4 additions & 1 deletion app/Jobs/AvatarPipeline/AvatarOptimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public function handle()

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)) {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/AvatarPipeline/CreateAvatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Profile $profile)
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;
Expand Down
10 changes: 8 additions & 2 deletions app/Observers/AvatarObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ public function deleted(Avatar $avatar)
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function likes()
public function avatar()
{
return $this->hasOne(Avatar::class)->withDefault([
'media_path' => 'public/avatars/default.png',
'media_path' => 'public/avatars/default.jpg',
'change_count' => 0
]);
}
Expand Down
2 changes: 2 additions & 0 deletions app/Util/Lexer/RestrictedNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class RestrictedNames
'api',
'audio',
'auth',
'avatar',
'avatars',
'b',
'bartender',
'broadcast',
Expand Down
3 changes: 2 additions & 1 deletion storage/app/public/avatars/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!.gitignore
!default.png
!default.png
!default.jpg
Binary file added storage/app/public/avatars/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified storage/app/public/avatars/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit f6528c8

@xundeenergie
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 58 and 59 in app/Console/Commands/AvatarDefaultMigration.php are duplicated and trailing || causes error on update avatar!
Remove them and the trailing || in line 57 then.

Please sign in to comment.