mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 08:13:16 +00:00
Remove identicons, use default avatar for new users
This commit is contained in:
parent
63f920a143
commit
541927634f
1 changed files with 1 additions and 62 deletions
|
@ -4,10 +4,6 @@ namespace App\Jobs\AvatarPipeline;
|
||||||
|
|
||||||
use App\Avatar;
|
use App\Avatar;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
use App\Util\Identicon\Preprocessor\HashPreprocessor;
|
|
||||||
use Bitverse\Identicon\Color\Color;
|
|
||||||
use Bitverse\Identicon\Generator\RingsGenerator;
|
|
||||||
use Bitverse\Identicon\Identicon;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
@ -45,64 +41,7 @@ class CreateAvatar implements ShouldQueue
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$profile = $this->profile;
|
$profile = $this->profile;
|
||||||
$username = $profile->username;
|
$path = 'public/avatars/default.png';
|
||||||
|
|
||||||
$generator = new RingsGenerator();
|
|
||||||
$generator->setBackgroundColor(Color::parseHex('#FFFFFF'));
|
|
||||||
|
|
||||||
$identicon = new Identicon(new HashPreprocessor('sha256'), $generator);
|
|
||||||
|
|
||||||
$hash = $username.str_random(12);
|
|
||||||
$icon = $identicon->getIcon($hash);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$baseDir = storage_path('app/public/avatars');
|
|
||||||
if (!is_dir($baseDir)) {
|
|
||||||
mkdir($baseDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
$prefix = $profile->id;
|
|
||||||
$padded = str_pad($prefix, 12, 0, STR_PAD_LEFT);
|
|
||||||
$parts = str_split($padded, 3);
|
|
||||||
foreach ($parts as $k => $part) {
|
|
||||||
if ($k == 0) {
|
|
||||||
$prefix = storage_path('app/public/avatars/'.$parts[0]);
|
|
||||||
if (!is_dir($prefix)) {
|
|
||||||
mkdir($prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($k == 1) {
|
|
||||||
$prefix = storage_path('app/public/avatars/'.$parts[0].'/'.$parts[1]);
|
|
||||||
if (!is_dir($prefix)) {
|
|
||||||
mkdir($prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($k == 2) {
|
|
||||||
$prefix = storage_path('app/public/avatars/'.$parts[0].'/'.$parts[1].'/'.$parts[2]);
|
|
||||||
if (!is_dir($prefix)) {
|
|
||||||
mkdir($prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($k == 3) {
|
|
||||||
$avatarpath = 'public/avatars/'.$parts[0].'/'.$parts[1].'/'.$parts[2].'/'.$parts[3];
|
|
||||||
$prefix = storage_path('app/'.$avatarpath);
|
|
||||||
if (!is_dir($prefix)) {
|
|
||||||
mkdir($prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dir = storage_path('app/'.$avatarpath);
|
|
||||||
//$dir = storage_path('app/public/avatars/'.$prefix);
|
|
||||||
if (!is_dir($dir)) {
|
|
||||||
mkdir($dir);
|
|
||||||
}
|
|
||||||
//$path = 'public/avatars/' . $prefix . '/avatar.svg';
|
|
||||||
$path = $avatarpath.'/avatar.svg';
|
|
||||||
$basePath = storage_path('app/'.$path);
|
|
||||||
file_put_contents($basePath, $icon);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
$avatar = new Avatar();
|
$avatar = new Avatar();
|
||||||
$avatar->profile_id = $profile->id;
|
$avatar->profile_id = $profile->id;
|
||||||
$avatar->media_path = $path;
|
$avatar->media_path = $path;
|
||||||
|
|
Loading…
Reference in a new issue