diff --git a/app/Support/LegacyAttachmentPathGenerator.php b/app/Support/LegacyAttachmentPathGenerator.php new file mode 100644 index 0000000..6ccbbee --- /dev/null +++ b/app/Support/LegacyAttachmentPathGenerator.php @@ -0,0 +1,39 @@ +getCustomProperty('legacy_filepath'); + if ($legacy) { + $legacy = ltrim($legacy, '/'); + $dir = dirname($legacy); + if ($dir !== '.') { + return $dir . '/'; + } + } + + return $media->id . '/'; + } + + public function getPathForConversions(Media $media): string + { + return $this->getPath($media) . 'conversions/'; + } + + public function getPathForResponsiveImages(Media $media): string + { + return $this->getPath($media) . 'responsive-images/'; + } +} diff --git a/config/media-library.php b/config/media-library.php index 04c97cd..b650e15 100644 --- a/config/media-library.php +++ b/config/media-library.php @@ -155,9 +155,7 @@ return [ * Here you can specify which path generator should be used for the given class. */ 'custom_path_generators' => [ - // Model::class => PathGenerator::class - // or - // 'model_morph_alias' => PathGenerator::class + \App\Models\Post::class => \App\Support\LegacyAttachmentPathGenerator::class, ], /*