diff --git a/app/Classes/AttachmentsManager.php b/app/Classes/AttachmentsManager.php index eb49409..029ffd3 100644 --- a/app/Classes/AttachmentsManager.php +++ b/app/Classes/AttachmentsManager.php @@ -6,6 +6,7 @@ use App\Classes\Traits\Repairs\RepairsImages; use App\Classes\Traits\Repairs\RepairsSounds; use App\Classes\Traits\Repairs\RepairsVideos; +use App\Exceptions\AttachmentNotFound; use App\View\Components\Image; use App\View\Components\Sound; use App\View\Components\Video; @@ -158,8 +159,8 @@ public function replaceAttachmentsInMarkdown(string $markdown) foreach ($matches[1] as $index => $ref) { try { - $component = $this->getComponentByRef($ref); - } catch (Exception $ex) { + $component = $this->getComponentByRef($ref, 'article'); + } catch (AttachmentNotFound $ex) { continue; } @@ -179,17 +180,15 @@ public function getComponentByRef(string $ref, ?string $filter = null) $variant = null; if (!empty($filter)) { - $variant = $this->getVariantData($ref, $filter); + $variant = $this->getVariantData($ref, $filter) ?? null; } // We set the fullname to the full path of the file in the filesystem // so the Blade component does not have to worry about it $attachment['filename'] = $this->getAttachmentFullPath($ref); - if (!empty($filter)) { + if (!empty($filter) && !empty($variant)) { $variant['filename'] = $this->getVariantFullPath($ref, $filter); - } else { - $variant = $attachment; } $component = $this->getBladeComponent($attachment, $variant); @@ -288,7 +287,7 @@ public function getAttachmentData(string $ref): array $data = $this->manager->get(sprintf('files.%s', $ref)); if (empty($data)) { - throw new Exception(sprintf('Unknown attachment %s', $ref)); + throw new AttachmentNotFound(sprintf('Unknown attachment %s', $ref)); } return $data; @@ -350,9 +349,9 @@ private function getBladeComponent(array $data, ?array $variant = []) case self::Images: return new Image($data, $variant); case self::Sounds: - return new Sound($data, $variant); + return new Sound($data); case self::Videos: - return new Video($data, $variant); + return new Video($data); default: throw new Exception(sprintf('Unknown Blade Component for attachment kind "%s"', $this->kind)); } diff --git a/app/Exceptions/AttachmentNotFound.php b/app/Exceptions/AttachmentNotFound.php new file mode 100644 index 0000000..856c147 --- /dev/null +++ b/app/Exceptions/AttachmentNotFound.php @@ -0,0 +1,10 @@ +