mirror of
https://github.com/flarum/framework.git
synced 2025-02-23 05:16:25 +08:00
Merge remote-tracking branch 'upstream/1.0.5'
This commit is contained in:
commit
d2fed4989f
@ -9,9 +9,13 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
|
use Flarum\Foundation\ValidationException;
|
||||||
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Illuminate\Contracts\Filesystem\Factory;
|
||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
use Intervention\Image\ImageManager;
|
use Intervention\Image\ImageManager;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class UploadFaviconController extends UploadImageController
|
class UploadFaviconController extends UploadImageController
|
||||||
{
|
{
|
||||||
@ -19,6 +23,22 @@ class UploadFaviconController extends UploadImageController
|
|||||||
|
|
||||||
protected $filenamePrefix = 'favicon';
|
protected $filenamePrefix = 'favicon';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var TranslatorInterface
|
||||||
|
*/
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SettingsRepositoryInterface $settings
|
||||||
|
* @param Factory $filesystemFactory
|
||||||
|
*/
|
||||||
|
public function __construct(SettingsRepositoryInterface $settings, Factory $filesystemFactory, TranslatorInterface $translator)
|
||||||
|
{
|
||||||
|
parent::__construct($settings, $filesystemFactory);
|
||||||
|
|
||||||
|
$this->translator = $translator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -27,8 +47,15 @@ class UploadFaviconController extends UploadImageController
|
|||||||
$this->fileExtension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
$this->fileExtension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
|
||||||
|
|
||||||
if ($this->fileExtension === 'ico') {
|
if ($this->fileExtension === 'ico') {
|
||||||
$encodedImage = $file->getStream();
|
// @todo remove in 2.0
|
||||||
} else {
|
throw new ValidationException([
|
||||||
|
'message' => strtr($this->translator->trans('validation.mimes'), [
|
||||||
|
':attribute' => 'favicon',
|
||||||
|
':values' => 'jpeg,png,gif,webp',
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$manager = new ImageManager();
|
$manager = new ImageManager();
|
||||||
|
|
||||||
$encodedImage = $manager->make($file->getStream())->resize(64, 64, function ($constraint) {
|
$encodedImage = $manager->make($file->getStream())->resize(64, 64, function ($constraint) {
|
||||||
@ -37,7 +64,6 @@ class UploadFaviconController extends UploadImageController
|
|||||||
})->encode('png');
|
})->encode('png');
|
||||||
|
|
||||||
$this->fileExtension = 'png';
|
$this->fileExtension = 'png';
|
||||||
}
|
|
||||||
|
|
||||||
return $encodedImage;
|
return $encodedImage;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user