增加 minio 策略的支持

This commit is contained in:
Wisp X 2022-03-05 20:51:11 +08:00
parent 072f4bff70
commit 9c7920049f
9 changed files with 112 additions and 15 deletions

View File

@ -23,7 +23,7 @@
- Email: i@wispx.cn
### 📌 TODO
* [ ] 支持多种第三方云储存本地、AWS S3、阿里云 OSS、腾讯云 COS、七牛云、又拍云、SFTP、FTP、WebDav
* [ ] 支持多种第三方云储存本地、AWS S3、阿里云 OSS、腾讯云 COS、七牛云、又拍云、SFTP、FTP、WebDav、Minio
* [x] 多图上传、拖拽上传、粘贴上传、复制、一键复制链接、页面响应式布局
* [x] 强大的图片管理功能,支持鼠标右键、单选多选、重命名等操作
* [x] 自由度极高的角色组配置,可以为每个组配置多个储存策略,同时储存策略可以配置多个角色组

View File

@ -0,0 +1,21 @@
<?php
namespace App\Enums\Strategy;
final class MinioOption
{
/** @var string 访问url */
const Url = 'url';
/** @var string AccessKey */
const AccessKey = 'access_key';
/** @var string SecretKey */
const SecretKey = 'secret_key';
/** @var string Endpoint */
const Endpoint = 'endpoint';
/** @var string Bucket */
const Bucket = 'bucket';
}

View File

@ -7,14 +7,11 @@ final class S3Option
/** @var string 访问url */
const Url = 'url';
/** @var string 根目录 */
const Root = 'root';
/** @var string AccessKeyId */
const AccessKeyId = 'access_key_id';
/** @var string Key */
const Key = 'access_key_id';
/** @var string Secret */
const Secret = 'secret_access_key';
/** @var string SecretAccessKey */
const SecretAccessKey = 'secret_access_key';
/** @var string 区域 */
const Region = 'region';

View File

@ -30,4 +30,7 @@ final class StrategyKey
/** @var int WebDav */
const Webdav = 9;
/** @var int Minio */
const Minio = 10;
}

View File

@ -73,7 +73,7 @@ class StrategyRequest extends FormRequest
StrategyKey::S3 => [
'configs.access_key_id' => 'required',
'configs.secret_access_key' => 'required',
'configs.region' => 'required',
'configs.region' => '',
'configs.bucket' => 'required',
],
StrategyKey::Oss => [
@ -118,6 +118,12 @@ class StrategyRequest extends FormRequest
'configs.username' => '',
'configs.password' => '',
],
StrategyKey::Minio => [
'configs.access_key' => 'required',
'configs.secret_key' => 'required',
'configs.endpoint' => 'required',
'configs.bucket' => 'required',
],
});
}
@ -182,6 +188,12 @@ class StrategyRequest extends FormRequest
'configs.username' => 'required',
'configs.password' => 'required',
],
StrategyKey::Minio => [
'configs.access_key' => 'AccessKey',
'configs.secret_key' => 'SecretKey',
'configs.endpoint' => '连接地址',
'configs.bucket' => 'Bucket 名称',
],
});
}
}

View File

@ -54,6 +54,7 @@ class Strategy extends Model
StrategyKey::Sftp => 'SFTP',
StrategyKey::Ftp => 'FTP',
StrategyKey::Webdav => 'WebDav',
StrategyKey::Minio => 'Minio',
];
protected static function booted()

View File

@ -12,6 +12,7 @@ use App\Enums\Strategy\CosOption;
use App\Enums\Strategy\FtpOption;
use App\Enums\Strategy\KodoOption;
use App\Enums\Strategy\LocalOption;
use App\Enums\Strategy\MinioOption;
use App\Enums\Strategy\OssOption;
use App\Enums\Strategy\S3Option;
use App\Enums\Strategy\SftpOption;
@ -225,10 +226,11 @@ class ImageService
StrategyKey::S3 => new AwsS3V3Adapter(
client: new S3Client([
'credentials' => [
'key' => $configs->get(S3Option::Key),
'secret' => $configs->get(S3Option::Secret)
'key' => $configs->get(S3Option::AccessKeyId),
'secret' => $configs->get(S3Option::SecretAccessKey)
],
'region' => $configs->get(S3Option::Region),
'version' => '2006-03-01',
]),
bucket: $configs->get(S3Option::Bucket),
visibility: new \League\Flysystem\AwsS3V3\PortableVisibilityConverter(Visibility::PUBLIC),
@ -288,7 +290,20 @@ class ImageService
'baseUri' => $configs->get(WebDavOption::BaseUri),
'userName' => $configs->get(WebDavOption::Username),
'password' => $configs->get(WebDavOption::Password)
]))
])),
StrategyKey::Minio => new AwsS3V3Adapter(
client: new S3Client([
'credentials' => [
'key' => $configs->get(MinioOption::AccessKey),
'secret' => $configs->get(MinioOption::SecretKey)
],
'endpoint' => $configs->get(MinioOption::Endpoint),
'region' => '',
'version' => '2006-03-01',
]),
bucket: $configs->get(MinioOption::Bucket),
visibility: new \League\Flysystem\AwsS3V3\PortableVisibilityConverter(Visibility::PUBLIC),
),
};
}

View File

@ -69,12 +69,12 @@
<x-input type="password" name="configs[secret_access_key]" id="configs[secret_access_key]" placeholder="请输入 SecretAccessKey" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[region]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>区域(region)</label>
<label for="configs[region]" class="block text-sm font-medium text-gray-700">区域(region)</label>
<x-input type="text" name="configs[region]" id="configs[region]" placeholder="请输入区域例如us-east-1" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[bucket]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>储存桶名称</label>
<x-input type="text" name="configs[bucket]" id="configs[bucket]" placeholder="请输入 Bucket 名称" />
<x-input type="text" name="configs[bucket]" id="configs[bucket]" placeholder="请输入储存桶名称" />
</div>
</div>
@ -249,6 +249,29 @@
<x-input type="password" name="configs[password]" id="configs[password]" placeholder="请输入密码" />
</div>
</div>
<div class="col-span-6 mb-4 hidden" data-driver="{{ \App\Enums\StrategyKey::Minio }}">
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[url]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>访问域名</label>
<x-input type="url" name="configs[url]" id="configs[url]" placeholder="请输入图片访问域名 http(s)://" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[endpoint]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>连接地址</label>
<x-input type="url" name="configs[endpoint]" id="configs[endpoint]" placeholder="请输入连接地址" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[access_key]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>AccessKey</label>
<x-input type="text" name="configs[access_key]" id="configs[access_key]" placeholder="请输入 AccessKey" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[secret_key]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>SecretKey</label>
<x-input type="password" name="configs[secret_key]" id="configs[secret_key]" placeholder="请输入 SecretKey" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[bucket]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>Bucket 名称</label>
<x-input type="text" name="configs[bucket]" id="configs[bucket]" placeholder="请输入 Bucket 名称" />
</div>
</div>
</div>
<div class="px-4 py-3 bg-gray-50 text-right sm:px-6">
<x-button type="button" class="bg-gray-500" onclick="history.go(-1)">取消</x-button>

View File

@ -75,7 +75,7 @@
<x-input type="password" name="configs[secret_access_key]" id="configs[secret_access_key]" placeholder="请输入 SecretAccessKey" value="{{ $strategy->configs['secret_access_key'] }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[region]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>区域(region)</label>
<label for="configs[region]" class="block text-sm font-medium text-gray-700">区域(region)</label>
<x-input type="text" name="configs[region]" id="configs[region]" placeholder="请输入区域例如us-east-1" value="{{ $strategy->configs['region'] }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
@ -268,6 +268,31 @@
</div>
</div>
@endif
@if($strategy->key === \App\Enums\StrategyKey::Minio)
<div class="col-span-6 mb-4" data-driver="{{ \App\Enums\StrategyKey::Minio }}">
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[url]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>访问域名</label>
<x-input type="url" name="configs[url]" id="configs[url]" placeholder="请输入图片访问域名 http(s)://" value="{{ $strategy->configs['url'] }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[endpoint]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>连接地址</label>
<x-input type="url" name="configs[endpoint]" id="configs[endpoint]" placeholder="请输入连接地址" value="{{ $strategy->configs['endpoint'] }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[access_key]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>AccessKey</label>
<x-input type="text" name="configs[access_key]" id="configs[access_key]" placeholder="请输入 AccessKey" value="{{ $strategy->configs['access_key'] }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[secret_key]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>SecretKey</label>
<x-input type="password" name="configs[secret_key]" id="configs[secret_key]" placeholder="请输入 SecretKey" value="{{ $strategy->configs['secret_key'] }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[bucket]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>储存桶名称</label>
<x-input type="text" name="configs[bucket]" id="configs[bucket]" placeholder="请输入 Bucket 名称" value="{{ $strategy->configs['bucket'] }}" />
</div>
</div>
@endif
</div>
<div class="px-4 py-3 bg-gray-50 text-right sm:px-6">
<x-button type="button" class="bg-gray-500" onclick="history.go(-1)">取消</x-button>