thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.81k stars 2.67k forks source link

Media Picker option "hide_thumbnails" doesn't work #5743

Open Corinthian72 opened 1 year ago

Corinthian72 commented 1 year ago

Laravel version

9.36.4

PHP version

8.1

Voyager version

1.6.0

Database

MySQL 5.7

Description

In VoyagerMediaController there is a condition that checks if file is a thumbnail.

if (Str::endsWith($item['path'], $thumbnail_names)) {
    $thumbnails[] = $item;
    continue;
}

But it doesn't work. Let's say my options for Media Picker field look like this

{
    "allowed": [
        "image"
    ],
    "hide_thumbnails": true,
    "thumbnails": [
        {
            "type": "resize",
            "name": "resize-max",
            "width": null,
            "height": 480,
            "upsize": false
        },
        {
            "type": "resize",
            "name": "resize-medium",
            "width": null,
            "height": 400,
            "upsize": false
        },
        {
            "type": "resize",
            "name": "resize-small",
            "width": null,
            "height": 282,
            "upsize": false
        }
    ]
}

In this case $thumbnail_names array will contain names "resize-max", "resize-medium", "resize-small"

If I upload file "example.jpg", three thumbnails will be automatically generated

But none of them will return true in thumbnail condition

Str::endsWith($item['path'], $thumbnail_names)

Because $item['path'] contains image path with file extention. "model/example-resize-max.jpg" does't end with "resize-max". It ends with "resize-max.jpg"

Steps to reproduce

Any Media Picker field with thumbnails. Option "hide_thumbnails" is true by default.

Expected behavior

Thumbnails must be hidden from Media Picker file list if "hide_thumbnails" is set to "true".

Screenshots

No response

Additional context

No response

toto975 commented 3 months ago

Hello,

Same issue for me. Here's a workaround. In VoyagerMediaController.php, change

                    if (Str::endsWith($item['path'], $thumbnail_names)) {
                        $thumbnails[] = $item;
                        continue;
                    }

to

                    if (Str::endsWith(pathinfo($item['path'])['filename'], $thumbnail_names)) {
                        continue;
                    }