Skip to content

Commit

Permalink
Merge pull request #80 from ConductionNL/feature/REGISTERS-66/encode
Browse files Browse the repository at this point in the history
Fix two small bugs
  • Loading branch information
rjzondervan authored Nov 30, 2024
2 parents 81246fa + 032715b commit fffa450
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Service/ObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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() ?? []);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fffa450

Please sign in to comment.