Skip to content

Commit 8ec1681

Browse files
committed
Fix thumbnail route
1 parent e847bdc commit 8ec1681

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/Controllers/Files.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php namespace Tatter\Files\Controllers;
22

33
use CodeIgniter\Controller;
4-
use CodeIgniter\Files\File;
4+
use CodeIgniter\Exceptions\PageNotFoundException;
55
use CodeIgniter\HTTP\RedirectResponse;
66
use CodeIgniter\HTTP\RequestInterface;
77
use CodeIgniter\HTTP\ResponseInterface;
88
use Psr\Log\LoggerInterface;
99
use Tatter\Files\Config\Files as FilesConfig;
1010
use Tatter\Files\Exceptions\FilesException;
11+
use Tatter\Files\Entities\File;
1112
use Tatter\Files\Models\FileModel;
1213

1314
class Files extends Controller
@@ -512,11 +513,18 @@ public function export(string $slug, $fileId): ResponseInterface
512513
*
513514
* @return ResponseInterface
514515
*/
515-
public function thumbnail($fileId)
516+
public function thumbnail($fileId): ResponseInterface
516517
{
517-
$file = $this->model->find($fileId);
518-
$data = $file->getThumbnail('raw');
519-
return $this->response->setHeader('Content-type', 'image/jpeg')->setBody($data);
518+
if ($file = $this->model->find($fileId))
519+
{
520+
$path = $file->getThumbnail();
521+
}
522+
else
523+
{
524+
$path = File::locateDefaultThumbnail();
525+
}
526+
527+
return $this->response->setHeader('Content-type', 'image/jpeg')->setBody(file_get_contents($path));
520528
}
521529

522530
//--------------------------------------------------------------------

src/Entities/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class File extends Entity
2727
*
2828
* @throws FileNotFoundException
2929
*/
30-
protected static function locateDefaultThumbnail(): string
30+
public static function locateDefaultThumbnail(): string
3131
{
3232
// If the path has not been resolved yet then try to now
3333
if (is_null(self::$defaultThumbnail))

0 commit comments

Comments
 (0)