|
|
@ -6,6 +6,8 @@ use App\Models\CustomEmoji;
|
|
|
|
use App\Util\ActivityPub\Helpers;
|
|
|
|
use App\Util\ActivityPub\Helpers;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
use Illuminate\Http\Client\RequestException;
|
|
|
|
|
|
|
|
|
|
|
|
class CustomEmojiService
|
|
|
|
class CustomEmojiService
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -33,7 +35,13 @@ class CustomEmojiService
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$res = Http::acceptJson()->get($url);
|
|
|
|
try {
|
|
|
|
|
|
|
|
$res = Http::acceptJson()->get($url);
|
|
|
|
|
|
|
|
} catch (RequestException $e) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($res->successful()) {
|
|
|
|
if($res->successful()) {
|
|
|
|
$json = $res->json();
|
|
|
|
$json = $res->json();
|
|
|
@ -57,16 +65,23 @@ class CustomEmojiService
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$emoji = new CustomEmoji;
|
|
|
|
$emoji = CustomEmoji::firstOrCreate([
|
|
|
|
$emoji->shortcode = $json['name'];
|
|
|
|
'shortcode' => $json['name'],
|
|
|
|
$emoji->uri = $json['id'];
|
|
|
|
'domain' => parse_url($json['id'], PHP_URL_HOST)
|
|
|
|
$emoji->domain = parse_url($json['id'], PHP_URL_HOST);
|
|
|
|
], [
|
|
|
|
$emoji->image_remote_url = $json['icon']['url'];
|
|
|
|
'uri' => $json['id'],
|
|
|
|
$emoji->save();
|
|
|
|
'image_remote_url' => $json['icon']['url']
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($emoji->wasRecentlyCreated == false) {
|
|
|
|
|
|
|
|
if(Storage::exists('public/' . $emoji->media_path)) {
|
|
|
|
|
|
|
|
Storage::delete('public/' . $emoji->media_path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$ext = '.' . last(explode('/', $json['icon']['mediaType']));
|
|
|
|
$ext = '.' . last(explode('/', $json['icon']['mediaType']));
|
|
|
|
$dest = storage_path('app/public/emoji/') . $emoji->id . $ext;
|
|
|
|
$dest = storage_path('app/public/emoji/') . $emoji->id . $ext;
|
|
|
|
copy($emoji->image_remote_url, $dest);
|
|
|
|
copy($json['icon']['url'], $dest);
|
|
|
|
$emoji->media_path = 'emoji/' . $emoji->id . $ext;
|
|
|
|
$emoji->media_path = 'emoji/' . $emoji->id . $ext;
|
|
|
|
$emoji->save();
|
|
|
|
$emoji->save();
|
|
|
|
|
|
|
|
|
|
|
@ -84,7 +99,13 @@ class CustomEmojiService
|
|
|
|
|
|
|
|
|
|
|
|
public static function headCheck($url)
|
|
|
|
public static function headCheck($url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$res = Http::head($url);
|
|
|
|
try {
|
|
|
|
|
|
|
|
$res = Http::head($url);
|
|
|
|
|
|
|
|
} catch (RequestException $e) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!$res->successful()) {
|
|
|
|
if(!$res->successful()) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|