策略增加原图保护功能

This commit is contained in:
Wisp X
2022-01-17 09:09:31 +08:00
parent 4cbdcf8354
commit 90eb5c71e9
3 changed files with 14 additions and 2 deletions
+3
View File
@@ -15,4 +15,7 @@ final class KodoOption
/** @var string Bucket */
const Bucket = 'bucket';
/** @var string 是否启用获取原始 url 功能 */
const IsEnableOriginUrl = 'is_enable_origin_url';
}
+3
View File
@@ -9,4 +9,7 @@ final class LocalOption
/** @var string 根目录 */
const Root = 'root';
/** @var string 是否启用获取原始 url 功能 */
const IsEnableOriginUrl = 'is_enable_origin_url';
}
+8 -2
View File
@@ -2,7 +2,9 @@
namespace App\Models;
use App\Enums\Strategy\LocalOption;
use App\Service\ImageService;
use App\Utils;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -111,8 +113,12 @@ class Image extends Model
if (!$this->strategy) {
return Storage::disk('uploads')->url($this->pathname);
}
$domain = rtrim($this->strategy->configs->get('domain'), '/');
return $domain.'/'.$this->pathname;
// 是否启用了获取图片直链功能
if ($this->strategy->configs->get(LocalOption::IsEnableOriginUrl)) {
return rtrim($this->strategy->configs->get(LocalOption::Domain), '/').'/'.$this->pathname;
} else {
return asset($this->pathname);
}
});
}