|
|
|
|
@ -2,7 +2,18 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Filesystem\FilesystemAdapter;
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use League\Flysystem\Filesystem as Flysystem;
|
|
|
|
|
use League\Flysystem\FilesystemAdapter as FlysystemAdapter;
|
|
|
|
|
use League\Flysystem\Local\LocalFilesystemAdapter as LocalAdapter;
|
|
|
|
|
use League\Flysystem\PathPrefixing\PathPrefixedAdapter;
|
|
|
|
|
use League\Flysystem\ReadOnly\ReadOnlyFilesystemAdapter;
|
|
|
|
|
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
|
|
|
|
|
use League\Flysystem\Visibility;
|
|
|
|
|
use League\MimeTypeDetection\ExtensionMimeTypeDetector;
|
|
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
@ -19,6 +30,46 @@ class AppServiceProvider extends ServiceProvider
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// 无 PHP fileinfo 时,Flysystem Local 适配器默认会用 FinfoMimeTypeDetector,会在构造时抛错。
|
|
|
|
|
// 使用仅按扩展名推断 MIME 的检测器,避免依赖 finfo(与启用 fileinfo 后的行为略有差异,可接受)。
|
|
|
|
|
if (! class_exists(\finfo::class)) {
|
|
|
|
|
Storage::extend('local', function ($app, array $config) {
|
|
|
|
|
$visibility = PortableVisibilityConverter::fromArray(
|
|
|
|
|
$config['permissions'] ?? [],
|
|
|
|
|
$config['directory_visibility'] ?? $config['visibility'] ?? Visibility::PRIVATE
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$links = ($config['links'] ?? null) === 'skip'
|
|
|
|
|
? LocalAdapter::SKIP_LINKS
|
|
|
|
|
: LocalAdapter::DISALLOW_LINKS;
|
|
|
|
|
|
|
|
|
|
$adapter = new LocalAdapter(
|
|
|
|
|
$config['root'],
|
|
|
|
|
$visibility,
|
|
|
|
|
$config['lock'] ?? LOCK_EX,
|
|
|
|
|
$links,
|
|
|
|
|
new ExtensionMimeTypeDetector(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (($config['read-only'] ?? false) === true) {
|
|
|
|
|
$adapter = new ReadOnlyFilesystemAdapter($adapter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! empty($config['prefix'])) {
|
|
|
|
|
$adapter = new PathPrefixedAdapter($adapter, $config['prefix']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$flysystem = new Flysystem($adapter, Arr::only($config, [
|
|
|
|
|
'directory_visibility',
|
|
|
|
|
'disable_asserts',
|
|
|
|
|
'retain_visibility',
|
|
|
|
|
'temporary_url',
|
|
|
|
|
'url',
|
|
|
|
|
'visibility',
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
return new FilesystemAdapter($flysystem, $adapter, $config);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|