Differential D10299 Diff 24797 src/applications/files/controller/PhabricatorFileTransformController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileTransformController.php
Show First 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | $file = id(new PhabricatorFileQuery()) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$file) { | if (!$file) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
// TODO: We could just delegate to the file view controller instead, | // TODO: We could just delegate to the file view controller instead, | ||||
// which would save the client a roundtrip, but is slightly more complex. | // which would save the client a roundtrip, but is slightly more complex. | ||||
$uri = $file->getBestURI(); | $uri = $file->getBestURI(); | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | |||||
// TODO: This is a bit iffy. Sometimes, getBestURI() returns a CDN URI | |||||
// (if the file is a viewable image) and sometimes a local URI (if not). | |||||
// For now, just detect which one we got and configure the response | |||||
// appropriately. In the long run, if this endpoint is served from a CDN | |||||
// domain, we can't issue a local redirect to an info URI (which is not | |||||
// present on the CDN domain). We probably never actually issue local | |||||
// redirects here anyway, since we only ever transform viewable images | |||||
// right now. | |||||
$is_external = strlen(id(new PhutilURI($uri))->getDomain()); | |||||
return id(new AphrontRedirectResponse()) | |||||
->setIsExternal($is_external) | |||||
->setURI($uri); | |||||
} | } | ||||
private function executePreviewTransform(PhabricatorFile $file, $size) { | private function executePreviewTransform(PhabricatorFile $file, $size) { | ||||
$xformer = new PhabricatorImageTransformer(); | $xformer = new PhabricatorImageTransformer(); | ||||
return $xformer->executePreviewTransform($file, $size); | return $xformer->executePreviewTransform($file, $size); | ||||
} | } | ||||
private function executeThumbTransform(PhabricatorFile $file, $x, $y) { | private function executeThumbTransform(PhabricatorFile $file, $x, $y) { | ||||
$xformer = new PhabricatorImageTransformer(); | $xformer = new PhabricatorImageTransformer(); | ||||
return $xformer->executeThumbTransform($file, $x, $y); | return $xformer->executeThumbTransform($file, $x, $y); | ||||
} | } | ||||
} | } |