Skip to content

Commit

Permalink
Use display_name property for name
Browse files Browse the repository at this point in the history
  • Loading branch information
Randy Čupić committed Sep 18, 2024
1 parent c0138e2 commit d5be939
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/Core/Provider/Cloudinary/Factory/RemoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function create($data): RemoteResourceValue
type: $this->resolveResourceType($data),
url: $this->resolveCorrectUrl($data),
md5: $this->resolveMd5($data),
name: pathinfo($cloudinaryRemoteId->getResourceId(), PATHINFO_FILENAME),
name: $this->resolveName($data),
originalFilename: $this->resolveOriginalFilename($data),
version: ($data['version'] ?? null) !== null ? (string) $data['version'] : null,
visibility: $this->resolveVisibility($data),
Expand Down Expand Up @@ -142,6 +142,18 @@ private function resolveMd5(array $data): string
return $this->fileHashFactory->createHash($url);
}

private function resolveName(array $data): string
{
$cloudinaryRemoteId = CloudinaryRemoteId::fromCloudinaryData($data);
$nameFromPublicId = pathinfo($cloudinaryRemoteId->getResourceId(), PATHINFO_FILENAME);

if ($this->folderMode === CloudinaryProvider::FOLDER_MODE_FIXED) {
return $nameFromPublicId;
}

return $data['display_name'] ?? $nameFromPublicId;
}

private function resolveOriginalFilename(array $data): string
{
if (($data['context']['custom']['original_filename'] ?? null) !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public static function createDataProvider(): array
[
[
'public_id' => 'other/c87hg9xfxrd4itiim3t0',
'display_name' => 'c87hg9affrd4tthg12a2',
'signature' => 'f8645b000be7d717599affc89a068157e4748276',
'format' => 'pdf',
'resource_type' => 'image',
Expand Down Expand Up @@ -196,6 +197,7 @@ public static function createDataProvider(): array
[
[
'public_id' => 'c87hg9xfxrd4itiim3t0',
'display_name' => 'my_video.mp4',
'version' => 13711295958,
'signature' => 'f8645b000be7d717599affc89a068157e4748276',
'width' => 864,
Expand All @@ -222,7 +224,7 @@ public static function createDataProvider(): array
type: 'video',
url: 'https://res.cloudinary.com/testcloud/video/upload/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
name: 'my_video.mp4',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
version: '13711295958',
size: 120253,
Expand Down

0 comments on commit d5be939

Please sign in to comment.