改进 WebDav 以适配多种认证方式。Fixes #497, #520

This commit is contained in:
熊孝兵
2023-03-17 08:46:05 +08:00
parent 2b90d5eb75
commit fbb022c877
8 changed files with 1092 additions and 1022 deletions

View File

@@ -15,4 +15,10 @@ final class WebDavOption
/** @var string 密码 */
const Password = 'password';
/** @var string 认证方式 */
const AuthType = 'auth_type';
/** @var string 地址前缀 */
const Prefix = 'prefix';
}

View File

@@ -124,6 +124,8 @@ class StrategyRequest extends FormRequest
'configs.base_uri' => 'required',
'configs.username' => '',
'configs.password' => '',
'configs.auth_type' => '',
'configs.prefix' => '',
],
StrategyKey::Minio => [
'configs.access_key' => 'required',
@@ -200,9 +202,11 @@ class StrategyRequest extends FormRequest
'configs.passive' => '被动模式',
],
StrategyKey::Webdav => [
'configs.base_uri' => 'required',
'configs.username' => 'required',
'configs.password' => 'required',
'configs.base_uri' => '连接地址',
'configs.username' => '用户名',
'configs.password' => '密码',
'configs.auth_type' => '认证方式',
'configs.prefix' => '前缀',
],
StrategyKey::Minio => [
'configs.access_key' => 'AccessKey',

View File

@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Carbon;
use Sabre\DAV\Client;
/**
* @property int $id
@@ -56,6 +57,13 @@ class Strategy extends Model
StrategyKey::Minio => 'Minio',
];
const WEBDAV_AUTH_TYPES = [
'' => 'Auto',
Client::AUTH_BASIC => 'Basic',
Client::AUTH_DIGEST => 'Digest',
Client::AUTH_NTLM => 'Ntlm',
];
protected static function booted()
{
static::saving(function (self $strategy) {

View File

@@ -52,8 +52,8 @@ use League\Flysystem\FilesystemException;
use League\Flysystem\Ftp\FtpAdapter;
use League\Flysystem\Ftp\FtpConnectionOptions;
use League\Flysystem\Local\LocalFilesystemAdapter;
use League\Flysystem\PhpseclibV2\SftpAdapter;
use League\Flysystem\PhpseclibV2\SftpConnectionProvider;
use League\Flysystem\PhpseclibV3\SftpAdapter;
use League\Flysystem\PhpseclibV3\SftpConnectionProvider;
use League\Flysystem\WebDAV\WebDAVAdapter;
use Overtrue\Flysystem\Cos\CosAdapter;
use Overtrue\Flysystem\Qiniu\QiniuAdapter;
@@ -338,11 +338,12 @@ class ImageService
'timeout' => 30,
]),
),
StrategyKey::Webdav => new WebDAVAdapter(new Client([
StrategyKey::Webdav => new WebDAVAdapter(new Client(([
'baseUri' => $configs->get(WebDavOption::BaseUri),
'userName' => $configs->get(WebDavOption::Username),
'password' => $configs->get(WebDavOption::Password)
])),
'password' => $configs->get(WebDavOption::Password),
'authType' => (int)$configs->get(WebDavOption::AuthType),
])), $configs->get(WebDavOption::Prefix) ?: ''),
StrategyKey::Minio => new AwsS3V3Adapter(
client: new S3Client([
'credentials' => [

2054
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,6 @@
namespace Database\Seeders;
use App\Enums\ConfigKey;
use App\Enums\StrategyKey;
use App\Models\Group;
use Illuminate\Database\Seeder;

View File

@@ -296,6 +296,18 @@
<label for="configs[base_uri]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>连接地址</label>
<x-input type="url" name="configs[base_uri]" id="configs[base_uri]" placeholder="请输入连接地址" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="webdav-configs[auth_type]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>认证方式</label>
<x-select id="webdav-auth-type" name="configs[auth_type]" select2>
@foreach(\App\Models\Strategy::WEBDAV_AUTH_TYPES as $key => $type)
<option value="{{ $key }}" {{ $loop->first ? 'selected' : '' }}>{{ $type }}</option>
@endforeach
</x-select>
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="webdav-configs[prefix]" class="block text-sm font-medium text-gray-700">路径前缀</label>
<x-input type="text" name="configs[prefix]" id="webdav-configs[prefix]" placeholder="请输入路径前缀"></x-input>
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[username]" class="block text-sm font-medium text-gray-700">用户名</label>
<x-input type="text" name="configs[username]" id="configs[username]" placeholder="请输入用户名" />

View File

@@ -316,6 +316,18 @@
<label for="configs[base_uri]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>连接地址</label>
<x-input type="url" name="configs[base_uri]" id="configs[base_uri]" placeholder="请输入连接地址" value="{{ $strategy->configs->get('base_uri') }}" />
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="webdav-configs[auth_type]" class="block text-sm font-medium text-gray-700"><span class="text-red-600">*</span>认证方式</label>
<x-select id="webdav-auth-type" name="configs[auth_type]" select2>
@foreach(\App\Models\Strategy::WEBDAV_AUTH_TYPES as $key => $type)
<option value="{{ $key }}" {{ $key == $strategy->configs->get('auth_type') ? 'selected' : '' }}>{{ $type }}</option>
@endforeach
</x-select>
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="webdav-configs[prefix]" class="block text-sm font-medium text-gray-700">路径前缀</label>
<x-input type="text" name="configs[prefix]" id="webdav-configs[prefix]" placeholder="请输入路径前缀" value="{{ $strategy->configs->get('prefix') }}"></x-input>
</div>
<div class="col-span-3 sm:col-span-2 mb-4">
<label for="configs[username]" class="block text-sm font-medium text-gray-700">用户名</label>
<x-input type="text" name="configs[username]" id="configs[username]" placeholder="请输入用户名" value="{{ $strategy->configs->get('username') }}" />