diff --git a/lib/Service/ObjectService.php b/lib/Service/ObjectService.php index 1c5d390..a6f13bf 100755 --- a/lib/Service/ObjectService.php +++ b/lib/Service/ObjectService.php @@ -555,7 +555,8 @@ private function handleObjectRelations(ObjectEntity $objectEntity, array $object * @return array Updated object data * @throws Exception|GuzzleException When file handling fails */ - private function handleFileProperty(ObjectEntity $objectEntity, array $object, string $propertyName): array { + private function handleFileProperty(ObjectEntity $objectEntity, array $object, string $propertyName): array + { $fileName = str_replace('.', '_', $propertyName); $objectDot = new Dot($object); @@ -632,6 +633,8 @@ private function handleFileProperty(ObjectEntity $objectEntity, array $object, s } catch (Exception|NotFoundExceptionInterface $e) { throw new Exception('Failed to download file from URL: ' . $e->getMessage()); } + } else if (str_contains($objectDot->get($propertyName), $this->urlGenerator->getBaseUrl()) === true) { + return $object; } else { throw new Exception('Invalid file format - must be base64 encoded or valid URL'); } @@ -659,9 +662,9 @@ private function handleFileProperty(ObjectEntity $objectEntity, array $object, s // Create or find ShareLink $share = $this->fileService->findShare(path: $filePath); if ($share !== null) { - $shareLink = $this->fileService->getShareLink($share); + $shareLink = $this->fileService->getShareLink($share).'/download'; } else { - $shareLink = $this->fileService->createShareLink(path: $filePath); + $shareLink = $this->fileService->createShareLink(path: $filePath).'/download'; } $filesDot = new Dot($objectEntity->getFiles() ?? []); @@ -691,6 +694,7 @@ private function handleFileProperty(ObjectEntity $objectEntity, array $object, s */ public function getObject(Register $register, Schema $schema, string $uuid, ?array $extend = []): ObjectEntity { + // Handle internal source if ($register->getSource() === 'internal' || $register->getSource() === '') { return $this->objectEntityMapper->findByUuid($register, $schema, $uuid);