mirror of
https://github.com/lsky-org/lsky-pro.git
synced 2025-01-08 11:57:52 +08:00
✨ 改进上传服务
This commit is contained in:
parent
d795171461
commit
7505616e3f
@ -14,6 +14,7 @@ use BenSampo\Enum\Enum;
|
||||
* @method static static IsAllowGuestUpload()
|
||||
* @method static static UserInitialCapacity()
|
||||
* @method static static MailConfigs()
|
||||
* @method static static GuestGroupConfigs()
|
||||
*/
|
||||
final class ConfigKey extends Enum
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ use BenSampo\Enum\Enum;
|
||||
* @method static static MaximumFileSize()
|
||||
* @method static static ConcurrentUploadNum()
|
||||
* @method static static IsUploadNeedsReview()
|
||||
* @method static static LimitPerMinute()
|
||||
* @method static static LimitPerHour()
|
||||
* @method static static LimitPerDay()
|
||||
* @method static static LimitPerWeek()
|
||||
|
@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\StrategyKey;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
@ -74,9 +76,13 @@ class Image extends Model
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
if (! $this->strategy) {
|
||||
return asset($this->pathname);
|
||||
return Storage::disk('uploads')->url($this->pathname);
|
||||
}
|
||||
$domain = Str::replaceFirst('/', '', $this->strategy->configs->get('domain'));
|
||||
if (StrategyKey::Local()->is($this->strategy->key)) {
|
||||
// 本地储存前缀必须是 uploads
|
||||
$domain .= '/uploads';
|
||||
}
|
||||
return $domain.'/'.$this->pathname;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ class UploadService
|
||||
// 默认使用本地储存策略
|
||||
$disk = collect([
|
||||
'driver' => StrategyKey::Local,
|
||||
'configs' => collect([LocalOption::Root => config('filesystems.disks.'.env('FILESYSTEM_DRIVER').'.root')]),
|
||||
'configs' => collect([LocalOption::Root => config('filesystems.disks.uploads.root')]),
|
||||
]);
|
||||
|
||||
if (! is_null($user)) {
|
||||
|
@ -42,17 +42,12 @@ return [
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'uploads' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/uploads'),
|
||||
'url' => env('APP_URL').'/uploads',
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
@ -67,7 +62,8 @@ return [
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
// public_path('storage') => storage_path('app/public'),
|
||||
public_path('uploads') => storage_path('app/uploads'),
|
||||
],
|
||||
|
||||
];
|
||||
|
1
public/uploads
Symbolic link
1
public/uploads
Symbolic link
@ -0,0 +1 @@
|
||||
/Users/wispx/Develop/Projects/lsky-pro/storage/app/uploads
|
Loading…
Reference in New Issue
Block a user