diff --git a/app/Models/Emote.php b/app/Models/Emote.php index 0f7cbed..2faa719 100644 --- a/app/Models/Emote.php +++ b/app/Models/Emote.php @@ -17,6 +17,7 @@ class Emote extends Model protected $casts = [ 'emote_id' => 'string', 'guild_id' => 'string', + 'image' => 'string', ]; public function logs() diff --git a/app/Services/UpdateEmoteImages.php b/app/Services/UpdateEmoteImages.php index 60e8005..81b27b1 100644 --- a/app/Services/UpdateEmoteImages.php +++ b/app/Services/UpdateEmoteImages.php @@ -2,6 +2,8 @@ namespace App\Services; +use App\Models\Emote; +use GuzzleHttp\Client; use Laracord\Services\Service; class UpdateEmoteImages extends Service @@ -9,7 +11,7 @@ class UpdateEmoteImages extends Service /** * The service interval. */ - protected int $interval = 600; // 10 minutes + protected int $interval = 5; // 10 minutes /** * Handle the service. @@ -22,8 +24,14 @@ class UpdateEmoteImages extends Service return; } + $client = new Client; + foreach ($guild->emojis as $emoji) { - $emote = \App\Models\Emote::where('emote_id', $emoji->id)->whereIn('type', ['ANIMATED', 'STATIC'])->whereNull('image')->first(); + $emote = Emote::where('emote_id', $emoji->id) + ->whereIn('type', ['ANIMATED', 'STATIC']) + ->whereNull('image') + ->first(); + if (! $emote) { continue; } @@ -32,11 +40,15 @@ class UpdateEmoteImages extends Service $url = "https://cdn.discordapp.com/emojis/{$emoji->id}.{$ext}"; try { - $client = new \GuzzleHttp\Client; $response = $client->get($url); if ($response->getStatusCode() === 200) { - $stream = $response->getBody()->detach(); - $emote->image = $stream; + $imageBinary = (string) $response->getBody(); + + if ($imageBinary === '') { + continue; + } + + $emote->image = base64_encode($imageBinary); $emote->save(); } } catch (\Exception $e) { diff --git a/database/migrations/2026_02_20_000000_change_emote_image_to_text.php b/database/migrations/2026_02_20_000000_change_emote_image_to_text.php new file mode 100644 index 0000000..712b6c1 --- /dev/null +++ b/database/migrations/2026_02_20_000000_change_emote_image_to_text.php @@ -0,0 +1,36 @@ +dropColumn('image'); + }); + + Schema::table('emotes', function (Blueprint $table) { + $table->text('image')->nullable()->after('type'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('emotes', function (Blueprint $table) { + $table->dropColumn('image'); + }); + + Schema::table('emotes', function (Blueprint $table) { + $table->binary('image')->nullable()->after('type'); + }); + } +}; diff --git a/resources/views/components/homepage.blade.php b/resources/views/components/homepage.blade.php index 643cbca..3cca32c 100644 --- a/resources/views/components/homepage.blade.php +++ b/resources/views/components/homepage.blade.php @@ -6,7 +6,18 @@ return $placeholderImage; } - $binary = (string) $image; + $value = (string) $image; + + if (str_starts_with($value, 'data:image/')) { + return $value; + } + + $binary = base64_decode($value, true); + + if ($binary === false || $binary === '') { + return $placeholderImage; + } + $mime = 'image/png'; if (str_starts_with($binary, 'GIF8')) {