diff --git a/app/Enums/ConfigKey.php b/app/Enums/ConfigKey.php index 6042a88e..7e7d27e6 100644 --- a/app/Enums/ConfigKey.php +++ b/app/Enums/ConfigKey.php @@ -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 { diff --git a/app/Enums/GroupConfigKey.php b/app/Enums/GroupConfigKey.php index fc6bcd94..5e21c7e6 100644 --- a/app/Enums/GroupConfigKey.php +++ b/app/Enums/GroupConfigKey.php @@ -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() diff --git a/app/Models/Image.php b/app/Models/Image.php index 739d63a2..fe679ac4 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -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; } diff --git a/app/Service/UploadService.php b/app/Service/UploadService.php index 4d7bf5d6..01d448bb 100644 --- a/app/Service/UploadService.php +++ b/app/Service/UploadService.php @@ -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)) { diff --git a/config/filesystems.php b/config/filesystems.php index 760ef972..4025acd6 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -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'), ], ]; diff --git a/public/uploads b/public/uploads new file mode 120000 index 00000000..8104187d --- /dev/null +++ b/public/uploads @@ -0,0 +1 @@ +/Users/wispx/Develop/Projects/lsky-pro/storage/app/uploads \ No newline at end of file