mirror of
https://github.com/flarum/core.git
synced 2025-10-27 05:31:29 +01:00
Use Laravel filesystem interface for assets and avatars (#2729)
* WIP: Use Laravel filesystem interface where possible * Drop vendorFilesystem * Support getting URL of cloud-based logo and favicon * FilesystemAdapter should always be cloud * Get base avatar URL from filesystem adapter * Restore deleted getAsset method Co-authored-by: Alexander Skvortsov <askvortsov1@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a2d77d7b81
commit
f67149bb06
@@ -9,17 +9,21 @@
|
||||
|
||||
namespace Flarum\User;
|
||||
|
||||
use Illuminate\Contracts\Filesystem\Factory;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Image;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
|
||||
class AvatarUploader
|
||||
{
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $uploadDir;
|
||||
|
||||
public function __construct(FilesystemInterface $uploadDir)
|
||||
public function __construct(Factory $filesystemFactory)
|
||||
{
|
||||
$this->uploadDir = $uploadDir;
|
||||
$this->uploadDir = $filesystemFactory->disk('flarum-avatars');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +56,7 @@ class AvatarUploader
|
||||
$avatarPath = $user->getRawOriginal('avatar_url');
|
||||
|
||||
$user->afterSave(function () use ($avatarPath) {
|
||||
if ($this->uploadDir->has($avatarPath)) {
|
||||
if ($this->uploadDir->exists($avatarPath)) {
|
||||
$this->uploadDir->delete($avatarPath);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ use Flarum\Foundation\EventGeneratorTrait;
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Group\Permission;
|
||||
use Flarum\Http\AccessToken;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\DisplayName\DriverInterface;
|
||||
@@ -32,6 +31,7 @@ use Flarum\User\Event\Registered;
|
||||
use Flarum\User\Event\Renamed;
|
||||
use Flarum\User\Exception\NotAuthenticatedException;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Illuminate\Contracts\Filesystem\Factory;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
@@ -312,7 +312,7 @@ class User extends AbstractModel
|
||||
public function getAvatarUrlAttribute(string $value = null)
|
||||
{
|
||||
if ($value && strpos($value, '://') === false) {
|
||||
return app(UrlGenerator::class)->to('forum')->path('assets/avatars/'.$value);
|
||||
return resolve(Factory::class)->disk('flarum-avatars')->url($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
@@ -24,10 +24,7 @@ use Flarum\User\DisplayName\UsernameDriver;
|
||||
use Flarum\User\Event\EmailChangeRequested;
|
||||
use Flarum\User\Event\Registered;
|
||||
use Flarum\User\Event\Saving;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Filesystem\Factory;
|
||||
use Illuminate\Support\Arr;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
|
||||
class UserServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
@@ -36,7 +33,6 @@ class UserServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerAvatarsFilesystem();
|
||||
$this->registerDisplayNameDrivers();
|
||||
$this->registerPasswordCheckers();
|
||||
|
||||
@@ -78,17 +74,6 @@ class UserServiceProvider extends AbstractServiceProvider
|
||||
$this->container->alias('flarum.user.display_name.driver', DriverInterface::class);
|
||||
}
|
||||
|
||||
protected function registerAvatarsFilesystem()
|
||||
{
|
||||
$avatarsFilesystem = function (Container $container) {
|
||||
return $container->make(Factory::class)->disk('flarum-avatars')->getDriver();
|
||||
};
|
||||
|
||||
$this->container->when(AvatarUploader::class)
|
||||
->needs(FilesystemInterface::class)
|
||||
->give($avatarsFilesystem);
|
||||
}
|
||||
|
||||
protected function registerPasswordCheckers()
|
||||
{
|
||||
$this->container->singleton('flarum.user.password_checkers', function () {
|
||||
|
||||
Reference in New Issue
Block a user