1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Don't require prototypes for "{image ...}"

Summary: Depends on D19194. Fixes T4190. This should be in good-enough shape now to release and support more generally.

Test Plan: Used `{image ...}` in remarkup.

Maniphest Tasks: T4190

Differential Revision: https://secure.phabricator.com/D19195
This commit is contained in:
epriestley 2018-03-08 06:59:06 -08:00
parent b30535a36f
commit 6095d88998

View file

@ -8,15 +8,6 @@ final class PhabricatorFileImageProxyController
} }
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$show_prototypes = PhabricatorEnv::getEnvConfig(
'phabricator.show-prototypes');
if (!$show_prototypes) {
throw new Exception(
pht('Show prototypes is disabled.
Set `phabricator.show-prototypes` to `true` to use the image proxy'));
}
$viewer = $request->getViewer(); $viewer = $request->getViewer();
$img_uri = $request->getStr('uri'); $img_uri = $request->getStr('uri');
@ -24,9 +15,16 @@ final class PhabricatorFileImageProxyController
PhabricatorEnv::requireValidRemoteURIForLink($img_uri); PhabricatorEnv::requireValidRemoteURIForLink($img_uri);
$uri = new PhutilURI($img_uri); $uri = new PhutilURI($img_uri);
$proto = $uri->getProtocol(); $proto = $uri->getProtocol();
if (!in_array($proto, array('http', 'https'))) {
$allowed_protocols = array(
'http',
'https',
);
if (!in_array($proto, $allowed_protocols)) {
throw new Exception( throw new Exception(
pht('The provided image URI must be either http or https')); pht(
'The provided image URI must use one of these protocols: %s.',
implode(', ', $allowed_protocols)));
} }
// Check if we already have the specified image URI downloaded // Check if we already have the specified image URI downloaded
@ -43,9 +41,9 @@ final class PhabricatorFileImageProxyController
->setURI($img_uri) ->setURI($img_uri)
->setTTL($ttl); ->setTTL($ttl);
// Cache missed, so we'll need to validate and download the image.
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$save_request = false; $save_request = false;
// Cache missed so we'll need to validate and download the image
try { try {
// Rate limit outbound fetches to make this mechanism less useful for // Rate limit outbound fetches to make this mechanism less useful for
// scanning networks and ports. // scanning networks and ports.
@ -60,6 +58,7 @@ final class PhabricatorFileImageProxyController
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
'canCDN' => true, 'canCDN' => true,
)); ));
if (!$file->isViewableImage()) { if (!$file->isViewableImage()) {
$mime_type = $file->getMimeType(); $mime_type = $file->getMimeType();
$engine = new PhabricatorDestructionEngine(); $engine = new PhabricatorDestructionEngine();
@ -67,15 +66,15 @@ final class PhabricatorFileImageProxyController
$file = null; $file = null;
throw new Exception( throw new Exception(
pht( pht(
'The URI "%s" does not correspond to a valid image file, got '. 'The URI "%s" does not correspond to a valid image file (got '.
'a file with MIME type "%s". You must specify the URI of a '. 'a file with MIME type "%s"). You must specify the URI of a '.
'valid image file.', 'valid image file.',
$uri, $uri,
$mime_type)); $mime_type));
} else {
$file->save();
} }
$file->save();
$external_request $external_request
->setIsSuccessful(1) ->setIsSuccessful(1)
->setFilePHID($file->getPHID()); ->setFilePHID($file->getPHID());
@ -84,8 +83,7 @@ final class PhabricatorFileImageProxyController
} catch (HTTPFutureHTTPResponseStatus $status) { } catch (HTTPFutureHTTPResponseStatus $status) {
$external_request $external_request
->setIsSuccessful(0) ->setIsSuccessful(0)
->setResponseMessage($status->getMessage()) ->setResponseMessage($status->getMessage());
->save();
$save_request = true; $save_request = true;
} catch (Exception $ex) { } catch (Exception $ex) {