Skip to content

Commit

Permalink
Fix two small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Nov 30, 2024
1 parent dc74503 commit 032715b
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 @@ -554,7 +554,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 @@ -631,6 +632,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 @@ -658,9 +661,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 @@ -690,6 +693,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 032715b

Please sign in to comment.