Skip to content

Commit

Permalink
little adjustments
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Feb 19, 2024
1 parent 525c922 commit ebc3642
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
13 changes: 10 additions & 3 deletions lib/Middleware/ExAppUIL10NMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use OC\Security\CSP\ContentSecurityPolicyNonceManager;

use OCA\AppAPI\Service\ExAppService;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Middleware;
use OCP\IRequest;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;

class ExAppUIL10NMiddleware extends Middleware {

Expand All @@ -26,6 +28,7 @@ public function __construct(
private readonly ContentSecurityPolicyNonceManager $nonceManager,
private readonly IAppManager $appManager,
private readonly ExAppService $exAppService,
private readonly LoggerInterface $logger,
) {
}

Expand All @@ -50,9 +53,13 @@ public function beforeOutput(Controller $controller, string $methodName, string
$availableLocales = $this->l10nFactory->findAvailableLanguages($appId);
if (in_array($lang, $availableLocales) && $lang !== 'en') {
$headPos = stripos($output, '</head>');
$l10nScriptSrc = $this->appManager->getAppWebPath($appId) . '/l10n/' . $lang . '.js';
$nonce = $this->nonceManager->getNonce();
$output = substr_replace($output, '<script nonce="'.$nonce.'" defer src="' . $l10nScriptSrc . '"></script>', $headPos, 0);
try {
$l10nScriptSrc = $this->appManager->getAppWebPath($appId) . '/l10n/' . $lang . '.js';
$nonce = $this->nonceManager->getNonce();
$output = substr_replace($output, '<script nonce="'.$nonce.'" defer src="' . $l10nScriptSrc . '"></script>', $headPos, 0);
} catch (AppPathNotFoundException) {
$this->logger->error(sprintf('Can not find translations for %s ExApp.', $appId));
}
}
}
return $output;
Expand Down
13 changes: 10 additions & 3 deletions lib/Middleware/ExAppUiMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use OCA\AppAPI\AppInfo\Application;

use OCA\AppAPI\Controller\TopMenuController;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;

class ExAppUiMiddleware extends Middleware {

Expand All @@ -24,6 +26,7 @@ public function __construct(
private readonly IFactory $l10nFactory,
private readonly ContentSecurityPolicyNonceManager $nonceManager,
private readonly IAppManager $appManager,
private readonly LoggerInterface $logger,
) {
}

Expand All @@ -46,9 +49,13 @@ public function beforeOutput(Controller $controller, string $methodName, string
$availableLocales = $this->l10nFactory->findAvailableLanguages($appId);
if (in_array($lang, $availableLocales) && $lang !== 'en') {
$headPos = stripos($output, '</head>');
$l10nScriptSrc = $this->appManager->getAppWebPath($appId) . '/l10n/' . $lang . '.js';
$nonce = $this->nonceManager->getNonce();
$output = substr_replace($output, '<script nonce="'.$nonce.'" defer src="' . $l10nScriptSrc . '"></script>', $headPos, 0);
try {
$l10nScriptSrc = $this->appManager->getAppWebPath($appId) . '/l10n/' . $lang . '.js';
$nonce = $this->nonceManager->getNonce();
$output = substr_replace($output, '<script nonce="'.$nonce.'" defer src="' . $l10nScriptSrc . '"></script>', $headPos, 0);
} catch (AppPathNotFoundException) {
$this->logger->error(sprintf('Can not find translations for %s ExApp.', $appId));
}
}
}
return $output;
Expand Down
6 changes: 1 addition & 5 deletions lib/Service/ExAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function unregisterExApp(string $appId): bool {
$this->textProcessingService->unregisterExAppTextProcessingProviders($appId);
$this->translationService->unregisterExAppTranslationProviders($appId);
$this->settingsService->unregisterExAppForms($appId);
$this->exAppArchiveFetcher->removeExAppL10NFolder($appId);
if ($this->exAppMapper->deleteExApp($appId) === 1) {
$this->removeExAppL10NFolder($appId);
$this->cache->remove('/exApp_' . $appId);
return true;
}
Expand Down Expand Up @@ -278,10 +278,6 @@ public function getLatestExAppInfoFromAppstore(string $appId, bool $extract_l10n
return null;
}

public function removeExAppL10NFolder(string $appId): void {
$this->exAppArchiveFetcher->removeExAppL10NFolder($appId);
}

private function resetCaches(): void {
$this->topMenuService->resetCacheEnabled();
$this->filesActionsMenuService->resetCacheEnabled();
Expand Down

0 comments on commit ebc3642

Please sign in to comment.