Page MenuHomePhabricator

D11668.id28080.diff
No OneTemporary

D11668.id28080.diff

diff --git a/src/applications/files/application/PhabricatorFilesApplication.php b/src/applications/files/application/PhabricatorFilesApplication.php
--- a/src/applications/files/application/PhabricatorFilesApplication.php
+++ b/src/applications/files/application/PhabricatorFilesApplication.php
@@ -76,9 +76,12 @@
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorFileDeleteController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorFileEditController',
'info/(?P<phid>[^/]+)/' => 'PhabricatorFileInfoController',
- 'data/(?P<key>[^/]+)/(?P<phid>[^/]+)/(?P<token>[^/]+)/.*'
- => 'PhabricatorFileDataController',
- 'data/(?P<key>[^/]+)/(?P<phid>[^/]+)/.*'
+ 'data/'.
+ '(?:@(?P<instance>[^/]+)/)?'.
+ '(?P<key>[^/]+)/'.
+ '(?P<phid>[^/]+)/'.
+ '(?:(?P<token>[^/]+)/)?'.
+ '.*'
=> 'PhabricatorFileDataController',
'proxy/' => 'PhabricatorFileProxyController',
'xform/(?P<transform>[^/]+)/(?P<phid>[^/]+)/(?P<key>[^/]+)/'
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -556,12 +556,52 @@
'You must save a file before you can generate a view URI.');
}
+ return $this->getCDNURI(null);
+ }
+
+ private function getCDNURI($token) {
$name = phutil_escape_uri($this->getName());
- $path = '/file/data/'.$this->getSecretKey().'/'.$this->getPHID().'/'.$name;
+ $parts = array();
+ $parts[] = 'file';
+ $parts[] = 'data';
+
+ // If this is an instanced install, add the instance identifier to the URI.
+ // Instanced configurations behind a CDN may not be able to control the
+ // request domain used by the CDN (as with AWS CloudFront). Embedding the
+ // instance identity in the path allows us to distinguish between requests
+ // originating from different instances but served through the same CDN.
+ $instance = PhabricatorEnv::getEnvConfig('cluster.instance');
+ if (strlen($instance)) {
+ $parts[] = '@'.$instance;
+ }
+
+ $parts[] = $this->getSecretKey();
+ $parts[] = $this->getPHID();
+ if ($token) {
+ $parts[] = $token;
+ }
+ $parts[] = $name;
+
+ $path = implode('/', $parts);
+
return PhabricatorEnv::getCDNURI($path);
}
+ /**
+ * Get the CDN URI for this file, including a one-time-use security token.
+ *
+ */
+ public function getCDNURIWithToken() {
+ if (!$this->getPHID()) {
+ throw new Exception(
+ 'You must save a file before you can generate a CDN URI.');
+ }
+
+ return $this->getCDNURI($this->generateOneTimeToken());
+ }
+
+
public function getInfoURI() {
return '/'.$this->getMonogram();
}
@@ -963,26 +1003,6 @@
return $token;
}
- /** Get the CDN uri for this file
- * This will generate a one-time-use token if
- * security.alternate_file_domain is set in the config.
- */
- public function getCDNURIWithToken() {
- if (!$this->getPHID()) {
- throw new Exception(
- 'You must save a file before you can generate a CDN URI.');
- }
- $name = phutil_escape_uri($this->getName());
-
- $path = '/file/data'
- .'/'.$this->getSecretKey()
- .'/'.$this->getPHID()
- .'/'.$this->generateOneTimeToken()
- .'/'.$name;
- return PhabricatorEnv::getCDNURI($path);
- }
-
-
/**
* Write the policy edge between this file and some object.

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 19, 2:00 PM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6732457
Default Alt Text
D11668.id28080.diff (3 KB)

Event Timeline