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