From 5b1ea8c8d502f069cdaf1ce004cdfa65f1e82538 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 9 Feb 2015 15:31:47 -0800 Subject: [PATCH] Pass instance through file transform URIs Summary: This makes thumbnail URIs work on instanced, CDN'd installs like Phacility cluster instances. Some of these transforms can proabably be removed, but the underlying code to generate the transform should be cleaned up too and we have some other tasks filed elsewhere about this anyway. Test Plan: CDN'd local install now loads thumbnails properly. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D11719 --- .../PhabricatorFilesApplication.php | 6 ++- .../files/storage/PhabricatorFile.php | 48 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/applications/files/application/PhabricatorFilesApplication.php b/src/applications/files/application/PhabricatorFilesApplication.php index 612917959b..0d50f313da 100644 --- a/src/applications/files/application/PhabricatorFilesApplication.php +++ b/src/applications/files/application/PhabricatorFilesApplication.php @@ -84,7 +84,11 @@ final class PhabricatorFilesApplication extends PhabricatorApplication { '.*' => 'PhabricatorFileDataController', 'proxy/' => 'PhabricatorFileProxyController', - 'xform/(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/' + 'xform/'. + '(?:@(?P[^/]+)/)?'. + '(?P[^/]+)/'. + '(?P[^/]+)/'. + '(?P[^/]+)/' => 'PhabricatorFileTransformController', 'uploaddialog/' => 'PhabricatorFileUploadDialogController', 'download/(?P[^/]+)/' => 'PhabricatorFileDialogController', diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index ff21193abc..d6ed7b33fd 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -620,46 +620,52 @@ final class PhabricatorFile extends PhabricatorFileDAO return (string) $uri; } - public function getProfileThumbURI() { - $path = '/file/xform/thumb-profile/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; + private function getTransformedURI($transform) { + $parts = array(); + $parts[] = 'file'; + $parts[] = 'xform'; + + $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); + if (strlen($instance)) { + $parts[] = '@'.$instance; + } + + $parts[] = $transform; + $parts[] = $this->getPHID(); + $parts[] = $this->getSecretKey(); + + $path = implode('/', $parts); + $path = $path.'/'; + return PhabricatorEnv::getCDNURI($path); } + public function getProfileThumbURI() { + return $this->getTransformedURI('thumb-profile'); + } + public function getThumb60x45URI() { - $path = '/file/xform/thumb-60x45/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; - return PhabricatorEnv::getCDNURI($path); + return $this->getTransformedURI('thumb-60x45'); } public function getThumb160x120URI() { - $path = '/file/xform/thumb-160x120/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; - return PhabricatorEnv::getCDNURI($path); + return $this->getTransformedURI('thumb-160x120'); } public function getPreview100URI() { - $path = '/file/xform/preview-100/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; - return PhabricatorEnv::getCDNURI($path); + return $this->getTransformedURI('preview-100'); } public function getPreview220URI() { - $path = '/file/xform/preview-220/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; - return PhabricatorEnv::getCDNURI($path); + return $this->getTransformedURI('preview-220'); } public function getThumb220x165URI() { - $path = '/file/xform/thumb-220x165/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; - return PhabricatorEnv::getCDNURI($path); + return $this->getTransfomredURI('thumb-220x165'); } public function getThumb280x210URI() { - $path = '/file/xform/thumb-280x210/'.$this->getPHID().'/' - .$this->getSecretKey().'/'; - return PhabricatorEnv::getCDNURI($path); + return $this->getTransformedURI('thumb-280x210'); } public function isViewableInBrowser() {