Compare commits

...

3 Commits

Author SHA1 Message Date
philipp lang 1f87dd9f5e Log wrong requests
continuous-integration/drone/push Build is passing Details
2024-10-08 14:02:22 +02:00
philipp lang bebeb8a817 update guzzle
continuous-integration/drone/push Build is passing Details
2023-02-12 00:26:17 +01:00
philipp lang ea7b2e57ec Add winter config
continuous-integration/drone/push Build is passing Details
2021-12-21 01:02:15 +01:00
5 changed files with 929 additions and 1023 deletions

View File

@ -2,6 +2,7 @@
namespace Aweos\Resizer; namespace Aweos\Resizer;
use Log;
use Aweos\Resizer\Classes\CacheManager; use Aweos\Resizer\Classes\CacheManager;
use Aweos\Resizer\Classes\FileObserver; use Aweos\Resizer\Classes\FileObserver;
use Aweos\Resizer\Classes\ImageResizer; use Aweos\Resizer\Classes\ImageResizer;
@ -54,9 +55,9 @@ class Plugin extends PluginBase
*/ */
public function boot() public function boot()
{ {
app()->bind(ImageResizer::class, function() { app()->bind(ImageResizer::class, function () {
$disk = (new File())->getDisk(); $disk = (new File())->getDisk();
$dir = (new File(['is_public' => true]))->getStorageDirectory().'c/'; $dir = (new File(['is_public' => true]))->getStorageDirectory() . 'c/';
$media = MediaLibrary::instance(); $media = MediaLibrary::instance();
return new ImageResizer($disk, $dir, $media); return new ImageResizer($disk, $dir, $media);
@ -64,27 +65,28 @@ class Plugin extends PluginBase
app()->bind('resize', fn () => app(CacheManager::class)); app()->bind('resize', fn () => app(CacheManager::class));
Event::listen('media.file.upload', function($widget, $filePath, $uploadedFile) { Event::listen('media.file.upload', function ($widget, $filePath, $uploadedFile) {
if ((new MediaPath($filePath))->shouldProcess()) { if ((new MediaPath($filePath))->shouldProcess()) {
Queue::push(ResizeJob::class, [$filePath], Setting::get('queue')); Queue::push(ResizeJob::class, [$filePath], Setting::get('queue'));
} }
}); });
Event::listen('media.file.delete', function($widget, $filePath) { Event::listen('media.file.delete', function ($widget, $filePath) {
app(FileObserver::class)->delete(new MediaPath($filePath)); app(FileObserver::class)->delete(new MediaPath($filePath));
app(CacheManager::class)->delete(new MediaPath($filePath)); app(CacheManager::class)->delete(new MediaPath($filePath));
}); });
Event::listen('media.file.move', function($widget, $old, $new) { Event::listen('media.file.move', function ($widget, $old, $new) {
app(FileObserver::class)->rename(new MediaPath($old), new MediaPath($new)); app(FileObserver::class)->rename(new MediaPath($old), new MediaPath($new));
app(CacheManager::class)->delete(new MediaPath($old)); app(CacheManager::class)->delete(new MediaPath($old));
}); });
Event::listen('media.file.rename', function($widget, $old, $new) { Event::listen('media.file.rename', function ($widget, $old, $new) {
app(FileObserver::class)->rename(new MediaPath($old), new MediaPath($new)); app(FileObserver::class)->rename(new MediaPath($old), new MediaPath($new));
app(CacheManager::class)->delete(new MediaPath($old)); app(CacheManager::class)->delete(new MediaPath($old));
}); });
} }
public function registerSettings() { public function registerSettings()
{
return [ return [
'resizer' => [ 'resizer' => [
'label' => 'Resizer Settings', 'label' => 'Resizer Settings',
@ -99,17 +101,22 @@ class Plugin extends PluginBase
]; ];
} }
public function registerMarkupTags() { public function registerMarkupTags()
{
return [ return [
'filters' => [ 'filters' => [
'resize' => fn ($media, $size = 'original', $sizes = null, $options = []) => app(CacheManager::class)->get( 'resize' => function ($media, $size = 'original', $sizes = null, $options = []) {
if (is_null($media)) {
Log::warning('Media not found in path ' . url()->current());
}
return app(CacheManager::class)->get(
new MediaPath($media), new MediaPath($media),
$size, $size,
$sizes, $sizes,
$options, $options,
) );
}
] ]
]; ];
} }
} }

View File

@ -2,7 +2,7 @@
"name": "aweos/oc-resizer-plugin", "name": "aweos/oc-resizer-plugin",
"type": "october-plugin", "type": "october-plugin",
"require": { "require": {
"guzzlehttp/guzzle": "^6.3", "guzzlehttp/guzzle": "^7.5",
"intervention/image": "^2.6" "intervention/image": "^2.6"
}, },
"require-dev": { "require-dev": {

1907
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false" <phpunit backupGlobals="false"
backupStaticAttributes="false" backupStaticAttributes="false"
bootstrap="../../../modules/system/tests/bootstrap.php" bootstrap="../../../tests/bootstrap.php"
colors="true" colors="true"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"

View File

@ -19,6 +19,10 @@ class TestCase extends PluginTestCase
Setting::set('queue', 'default'); Setting::set('queue', 'default');
$this->media = MediaLibrary::instance(); $this->media = MediaLibrary::instance();
$pluginManager = PluginManager::instance();
$pluginManager->registerAll(true);
$pluginManager->bootAll(true);
} }
public function assertHasFile($file): void public function assertHasFile($file): void