|
|
|
@ -27,9 +27,9 @@ class MediaStorageService {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function avatar($avatar)
|
|
|
|
|
public static function avatar($avatar, $local = false)
|
|
|
|
|
{
|
|
|
|
|
return (new self())->fetchAvatar($avatar);
|
|
|
|
|
return (new self())->fetchAvatar($avatar, $local);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function head($url)
|
|
|
|
@ -177,11 +177,12 @@ class MediaStorageService {
|
|
|
|
|
unlink($tmpName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function fetchAvatar($avatar)
|
|
|
|
|
protected function fetchAvatar($avatar, $local = false)
|
|
|
|
|
{
|
|
|
|
|
$url = $avatar->remote_url;
|
|
|
|
|
$driver = $local ? 'local' : config('filesystems.cloud');
|
|
|
|
|
|
|
|
|
|
if($url == null || Helpers::validateUrl($url) == false) {
|
|
|
|
|
if(empty($url) || Helpers::validateUrl($url) == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -220,7 +221,7 @@ class MediaStorageService {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$base = 'cache/avatars/' . $avatar->profile_id;
|
|
|
|
|
$base = ($local ? 'public/cache/' : 'cache/') . 'avatars/' . $avatar->profile_id;
|
|
|
|
|
$ext = $head['mime'] == 'image/jpeg' ? 'jpg' : 'png';
|
|
|
|
|
$path = Str::random(20) . '_avatar.' . $ext;
|
|
|
|
|
$tmpBase = storage_path('app/remcache/');
|
|
|
|
@ -229,7 +230,7 @@ class MediaStorageService {
|
|
|
|
|
$data = file_get_contents($url, false, null, 0, $head['length']);
|
|
|
|
|
file_put_contents($tmpName, $data);
|
|
|
|
|
|
|
|
|
|
$disk = Storage::disk(config('filesystems.cloud'));
|
|
|
|
|
$disk = Storage::disk($driver);
|
|
|
|
|
$file = $disk->putFileAs($base, new File($tmpName), $path, 'public');
|
|
|
|
|
$permalink = $disk->url($file);
|
|
|
|
|
|
|
|
|
|