mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Don't do image stuff with unviewable images
Summary: If a file isn't a viewable image, don't try to figure out metadata (size, etc.) when rendering a `{F...}` tag in Remarkup. Test Plan: Uploaded a .rtf, added it as `{F1}` in a new Maniphest task, saw no errors in the dark console. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2479 Differential Revision: https://secure.phabricator.com/D4837
This commit is contained in:
parent
361ce491f2
commit
fb7d5d17a2
1 changed files with 28 additions and 24 deletions
|
@ -50,37 +50,41 @@ final class PhabricatorRemarkupRuleEmbedFile
|
|||
$file_name = coalesce($options['name'], $file->getName());
|
||||
$options['name'] = $file_name;
|
||||
|
||||
$is_viewable_image = $file->isViewableImage();
|
||||
|
||||
$attrs = array();
|
||||
switch ((string)$options['size']) {
|
||||
case 'full':
|
||||
$attrs['src'] = $file->getBestURI();
|
||||
$options['image_class'] = null;
|
||||
$file_data = $file->getMetadata();
|
||||
$height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT);
|
||||
if ($height) {
|
||||
$attrs['height'] = $height;
|
||||
}
|
||||
$width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH);
|
||||
if ($width) {
|
||||
$attrs['width'] = $width;
|
||||
}
|
||||
break;
|
||||
case 'thumb':
|
||||
default:
|
||||
$attrs['src'] = $file->getPreview220URI();
|
||||
$dimensions =
|
||||
PhabricatorImageTransformer::getPreviewDimensions($file, 220);
|
||||
$attrs['width'] = $dimensions['sdx'];
|
||||
$attrs['height'] = $dimensions['sdy'];
|
||||
$options['image_class'] = 'phabricator-remarkup-embed-image';
|
||||
break;
|
||||
if ($is_viewable_image) {
|
||||
switch ((string)$options['size']) {
|
||||
case 'full':
|
||||
$attrs['src'] = $file->getBestURI();
|
||||
$options['image_class'] = null;
|
||||
$file_data = $file->getMetadata();
|
||||
$height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT);
|
||||
if ($height) {
|
||||
$attrs['height'] = $height;
|
||||
}
|
||||
$width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH);
|
||||
if ($width) {
|
||||
$attrs['width'] = $width;
|
||||
}
|
||||
break;
|
||||
case 'thumb':
|
||||
default:
|
||||
$attrs['src'] = $file->getPreview220URI();
|
||||
$dimensions =
|
||||
PhabricatorImageTransformer::getPreviewDimensions($file, 220);
|
||||
$attrs['width'] = $dimensions['sdx'];
|
||||
$attrs['height'] = $dimensions['sdy'];
|
||||
$options['image_class'] = 'phabricator-remarkup-embed-image';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$bundle['attrs'] = $attrs;
|
||||
$bundle['options'] = $options;
|
||||
|
||||
$bundle['meta'] = array(
|
||||
'phid' => $file->getPHID(),
|
||||
'viewable' => $file->isViewableImage(),
|
||||
'viewable' => $is_viewable_image,
|
||||
'uri' => $file->getBestURI(),
|
||||
'dUri' => $file->getDownloadURI(),
|
||||
'name' => $options['name'],
|
||||
|
|
Loading…
Reference in a new issue