Skip to content

Commit

Permalink
Fix non images files file format/extension – Fixes #1412
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Apr 20, 2017
1 parent dab8c16 commit d26d1c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions api/core/Directus/Bootstrap.php
Expand Up @@ -24,6 +24,7 @@
use Directus\Exception\ForbiddenException;
use Directus\Filesystem\Filesystem;
use Directus\Filesystem\FilesystemFactory;
use Directus\Filesystem\Thumbnail;
use Directus\Hook\Emitter;
use Directus\Language\LanguageManager;
use Directus\Permissions\Acl;
Expand Down Expand Up @@ -649,7 +650,7 @@ private static function hookEmitter()
$addFilesUrl = function($result) {
$fileRows = $result->toArray();
$app = Bootstrap::get('app');
$files = $app->container->get('files');

foreach ($fileRows as &$row) {
$config = Bootstrap::get('config');
$fileURL = $config['filesystem']['root_url'];
Expand All @@ -658,8 +659,8 @@ private static function hookEmitter()
$thumbnailExtension = array_pop($thumbnailFilenameParts);

$row['url'] = $fileURL . '/' . $row['name'];
if (in_array($thumbnailExtension, ['tif', 'tiff', 'psd', 'pdf'])) {
$thumbnailExtension = 'jpg';
if (Thumbnail::isNonImageFormatSupported($thumbnailExtension)) {
$thumbnailExtension = Thumbnail::defaultFormat();
}

$thumbnailFilename = $row['id'] . '.' . $thumbnailExtension;
Expand Down
8 changes: 4 additions & 4 deletions api/core/Directus/Database/TableGateway/BaseTableGateway.php
Expand Up @@ -353,17 +353,17 @@ public function addOrUpdateRecordByArray(array $recordData, $tableName = null)

if ($tableName == 'directus_files' && static::$container) {
$Files = static::$container->get('files');
$ext = pathinfo($recordData['name'], PATHINFO_EXTENSION);
$ext = $thumbnailExt = pathinfo($recordData['name'], PATHINFO_EXTENSION);

// hotfix: pdf thumbnails are being saved to its original extension
// file.pdf results into a thumbs/thumb.pdf instead of thumbs/thumb.jpeg
if (Thumbnail::isNonImageFormatSupported($ext)) {
$ext = Thumbnail::defaultFormat();
if (Thumbnail::isNonImageFormatSupported($thumbnailExt)) {
$thumbnailExt = Thumbnail::defaultFormat();
}

$thumbnailPath = 'thumbs/THUMB_' . $recordData['name'];
if ($Files->exists($thumbnailPath)) {
$Files->rename($thumbnailPath, 'thumbs/' . $recordData[$this->primaryKeyFieldName] . '.' . $ext);
$Files->rename($thumbnailPath, 'thumbs/' . $recordData[$this->primaryKeyFieldName] . '.' . $thumbnailExt);
}

$updateArray = [];
Expand Down

0 comments on commit d26d1c2

Please sign in to comment.