mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Improve package resolution APIs on CelerityResourceMap
Summary: Ref T4222. A few diffs from now, `CelerityResourceMap` will have a `CelerityResources` inside of it: - Rename `resolvePackage()` to `getResourceNamesForPackageHash()`. This isn't a functional change, it's just making it clear what it does. - Add `getResourceDataForName()`, to push details about storage into `CelerityResources`. Test Plan: Reloaded a bunch of pages, rebuilt map. Reviewers: btrahan, hach-que Reviewed By: hach-que CC: aran Maniphest Tasks: T4222 Differential Revision: https://secure.phabricator.com/D7869
This commit is contained in:
parent
60ff29ed06
commit
59ad78d4ab
2 changed files with 14 additions and 13 deletions
|
@ -16,10 +16,6 @@ abstract class CelerityResourceController extends PhabricatorController {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function getDiskPath($to_resource = null) {
|
||||
return $this->getRootDirectory().$to_resource;
|
||||
}
|
||||
|
||||
protected function serveResource($path, $package_hash = null) {
|
||||
// Sanity checking to keep this from exposing anything sensitive, since it
|
||||
// ultimately boils down to disk reads.
|
||||
|
@ -41,18 +37,18 @@ abstract class CelerityResourceController extends PhabricatorController {
|
|||
return $this->makeResponseCacheable(new Aphront304Response());
|
||||
}
|
||||
|
||||
if ($package_hash) {
|
||||
$map = CelerityResourceMap::getInstance();
|
||||
$paths = $map->resolvePackage($package_hash);
|
||||
if (!$paths) {
|
||||
|
||||
if ($package_hash) {
|
||||
$resource_names = $map->getResourceNamesForPackageHash($package_hash);
|
||||
if (!$resource_names) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
try {
|
||||
$data = array();
|
||||
foreach ($paths as $package_path) {
|
||||
$disk_path = $this->getDiskPath($package_path);
|
||||
$data[] = Filesystem::readFile($disk_path);
|
||||
foreach ($resource_names as $resource_name) {
|
||||
$data[] = $map->getResourceDataForName($resource_name);
|
||||
}
|
||||
$data = implode("\n\n", $data);
|
||||
} catch (Exception $ex) {
|
||||
|
@ -60,8 +56,7 @@ abstract class CelerityResourceController extends PhabricatorController {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
$disk_path = $this->getDiskPath($path);
|
||||
$data = Filesystem::readFile($disk_path);
|
||||
$data = $map->getResourceDataForName($path);
|
||||
} catch (Exception $ex) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
|
|
@ -90,7 +90,13 @@ final class CelerityResourceMap {
|
|||
return $packaged;
|
||||
}
|
||||
|
||||
public function resolvePackage($package_hash) {
|
||||
public function getResourceDataForName($resource_name) {
|
||||
$root = phutil_get_library_root('phabricator');
|
||||
$root = dirname($root).'/webroot/';
|
||||
return Filesystem::readFile($root.$resource_name);
|
||||
}
|
||||
|
||||
public function getResourceNamesForPackageHash($package_hash) {
|
||||
$package = idx($this->packageMap['packages'], $package_hash);
|
||||
if (!$package) {
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue