1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 10:16:09 +02: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:
Alexander Skvortsov
2021-04-19 15:11:03 -04:00
committed by GitHub
parent a2d77d7b81
commit f67149bb06
13 changed files with 82 additions and 92 deletions

View File

@@ -11,8 +11,9 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Laminas\Diactoros\Response\EmptyResponse;
use League\Flysystem\FilesystemInterface;
use Psr\Http\Message\ServerRequestInterface;
class DeleteFaviconController extends AbstractDeleteController
@@ -23,18 +24,18 @@ class DeleteFaviconController extends AbstractDeleteController
protected $settings;
/**
* @var FilesystemInterface
* @var Filesystem
*/
protected $uploadDir;
/**
* @param SettingsRepositoryInterface $settings
* @param FilesystemInterface $uploadDir
* @param Factory $filesystemFactory
*/
public function __construct(SettingsRepositoryInterface $settings, FilesystemInterface $uploadDir)
public function __construct(SettingsRepositoryInterface $settings, Factory $filesystemFactory)
{
$this->settings = $settings;
$this->uploadDir = $uploadDir;
$this->uploadDir = $filesystemFactory->disk('flarum-assets');
}
/**
@@ -48,7 +49,7 @@ class DeleteFaviconController extends AbstractDeleteController
$this->settings->set('favicon_path', null);
if ($this->uploadDir->has($path)) {
if ($this->uploadDir->exists($path)) {
$this->uploadDir->delete($path);
}

View File

@@ -11,8 +11,9 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Laminas\Diactoros\Response\EmptyResponse;
use League\Flysystem\FilesystemInterface;
use Psr\Http\Message\ServerRequestInterface;
class DeleteLogoController extends AbstractDeleteController
@@ -23,18 +24,18 @@ class DeleteLogoController extends AbstractDeleteController
protected $settings;
/**
* @var FilesystemInterface
* @var Filesystem
*/
protected $uploadDir;
/**
* @param SettingsRepositoryInterface $settings
* @param FilesystemInterface $uploadDir
* @param Factory $filesystemFactory
*/
public function __construct(SettingsRepositoryInterface $settings, FilesystemInterface $uploadDir)
public function __construct(SettingsRepositoryInterface $settings, Factory $filesystemFactory)
{
$this->settings = $settings;
$this->uploadDir = $uploadDir;
$this->uploadDir = $filesystemFactory->disk('flarum-assets');
}
/**
@@ -48,7 +49,7 @@ class DeleteLogoController extends AbstractDeleteController
$this->settings->set('logo_path', null);
if ($this->uploadDir->has($path)) {
if ($this->uploadDir->exists($path)) {
$this->uploadDir->delete($path);
}

View File

@@ -11,10 +11,11 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Intervention\Image\Image;
use League\Flysystem\FilesystemInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Tobscure\JsonApi\Document;
@@ -27,7 +28,7 @@ abstract class UploadImageController extends ShowForumController
protected $settings;
/**
* @var FilesystemInterface
* @var Filesystem
*/
protected $uploadDir;
@@ -48,12 +49,12 @@ abstract class UploadImageController extends ShowForumController
/**
* @param SettingsRepositoryInterface $settings
* @param FilesystemInterface $uploadDir
* @param Factory $filesystemFactory
*/
public function __construct(SettingsRepositoryInterface $settings, FilesystemInterface $uploadDir)
public function __construct(SettingsRepositoryInterface $settings, Factory $filesystemFactory)
{
$this->settings = $settings;
$this->uploadDir = $uploadDir;
$this->uploadDir = $filesystemFactory->disk('flarum-assets');
}
/**
@@ -73,7 +74,7 @@ abstract class UploadImageController extends ShowForumController
$uploadName = $this->filenamePrefix.'-'.Str::lower(Str::random(8)).'.'.$this->fileExtension;
$this->uploadDir->write($uploadName, $encodedImage);
$this->uploadDir->put($uploadName, $encodedImage);
$this->settings->set($this->filePathSettingKey, $uploadName);