aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFerdinand Thiessen <rpm@fthiessen.de>2023-01-10 03:04:58 +0100
committerFerdinand Thiessen <rpm@fthiessen.de>2023-02-22 21:19:37 +0100
commita3595f73acb538df0f3df96418d066d6a3ce60b8 (patch)
treeefda194c0ba134529a5022cd1299385ab0daaf2d /lib
parentb642137c652e5262c88dd4ddc055df684c8da8a2 (diff)
downloadnextcloud-server-a3595f73acb538df0f3df96418d066d6a3ce60b8.tar.gz
nextcloud-server-a3595f73acb538df0f3df96418d066d6a3ce60b8.zip
fix(OC/Template): Allow `.mjs` files within custom app paths
If apps are installed in non standard app paths, we need to check `$app_path/$script` instead of only doing so for translations. Without this it would fallback to `.js` extension even if a `.mjs` file exists. Also tried make the code more selfe explaining. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Template/JSResourceLocator.php50
1 files changed, 21 insertions, 29 deletions
diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php
index 4b41e51ae14..120234146e1 100644
--- a/lib/private/Template/JSResourceLocator.php
+++ b/lib/private/Template/JSResourceLocator.php
@@ -28,15 +28,12 @@
namespace OC\Template;
use OCP\App\AppPathNotFoundException;
+use OCP\App\IAppManager;
use Psr\Log\LoggerInterface;
-use \OCP\App\IAppManager;
class JSResourceLocator extends ResourceLocator {
- /** @var JSCombiner */
- protected $jsCombiner;
-
- /** @var IAppManager */
- protected $appManager;
+ protected JSCombiner $jsCombiner;
+ protected IAppManager $appManager;
public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner, IAppManager $appManager) {
parent::__construct($logger);
@@ -86,41 +83,36 @@ class JSResourceLocator extends ResourceLocator {
}
$script = substr($script, strpos($script, '/') + 1);
- $app_path = false;
- $app_url = false;
+ $app_url = null;
try {
- $app_path = $this->appManager->getAppPath($app);
- // Account for the possibility of having symlinks in app path. Only
- // do this if $app_path is set, because an empty argument to realpath
- // gets turned into cwd.
- $app_path = realpath($app_path);
+ $app_url = $this->appManager->getAppWebPath($app);
} catch (AppPathNotFoundException) {
// pass
}
try {
- $app_url = $this->appManager->getAppWebPath($app);
- } catch (AppPathNotFoundException) {
- // pass
- }
+ $app_path = $this->appManager->getAppPath($app);
- // missing translations files fill be ignored
- if (strpos($script, 'l10n/') === 0) {
- $this->appendScriptIfExist($app_path, $script, $app_url);
- return;
- }
+ // Account for the possibility of having symlinks in app path. Only
+ // do this if $app_path is set, because an empty argument to realpath
+ // gets turned into cwd.
+ $app_path = realpath($app_path);
- if ($app_path === false && $app_url === false) {
+ // missing translations files will be ignored
+ if (strpos($script, 'l10n/') === 0) {
+ $this->appendScriptIfExist($app_path, $script, $app_url);
+ return;
+ }
+
+ if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
+ $this->appendScriptIfExist($app_path, $script, $app_url);
+ }
+ } catch (AppPathNotFoundException) {
$this->logger->error('Could not find resource {resource} to load', [
'resource' => $app . '/' . $script . '.js',
'app' => 'jsresourceloader',
]);
- return;
- }
-
- if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
- $this->append($app_path, $script . '.js', $app_url);
}
}
@@ -134,7 +126,7 @@ class JSResourceLocator extends ResourceLocator {
* Try to find ES6 script file (`.mjs`) with fallback to plain javascript (`.js`)
* @see appendIfExist()
*/
- protected function appendScriptIfExist($root, $file, $webRoot = null) {
+ protected function appendScriptIfExist(string $root, string $file, string $webRoot = null) {
if (!$this->appendIfExist($root, $file . '.mjs', $webRoot)) {
return $this->appendIfExist($root, $file . '.js', $webRoot);
}