OCJSController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Core\Controller;
  7. use bantu\IniGetWrapper\IniGetWrapper;
  8. use OC\Authentication\Token\IProvider;
  9. use OC\CapabilitiesManager;
  10. use OC\Files\FilenameValidator;
  11. use OC\Template\JSConfigHelper;
  12. use OCP\App\IAppManager;
  13. use OCP\AppFramework\Controller;
  14. use OCP\AppFramework\Http;
  15. use OCP\AppFramework\Http\Attribute\FrontpageRoute;
  16. use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
  17. use OCP\AppFramework\Http\Attribute\OpenAPI;
  18. use OCP\AppFramework\Http\Attribute\PublicPage;
  19. use OCP\AppFramework\Http\DataDisplayResponse;
  20. use OCP\Defaults;
  21. use OCP\IConfig;
  22. use OCP\IGroupManager;
  23. use OCP\IInitialStateService;
  24. use OCP\IRequest;
  25. use OCP\ISession;
  26. use OCP\IURLGenerator;
  27. use OCP\IUserSession;
  28. use OCP\L10N\IFactory;
  29. use OCP\ServerVersion;
  30. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  31. class OCJSController extends Controller {
  32. private JSConfigHelper $helper;
  33. public function __construct(
  34. string $appName,
  35. IRequest $request,
  36. IFactory $l10nFactory,
  37. Defaults $defaults,
  38. IAppManager $appManager,
  39. ISession $session,
  40. IUserSession $userSession,
  41. IConfig $config,
  42. IGroupManager $groupManager,
  43. IniGetWrapper $iniWrapper,
  44. IURLGenerator $urlGenerator,
  45. CapabilitiesManager $capabilitiesManager,
  46. IInitialStateService $initialStateService,
  47. IProvider $tokenProvider,
  48. FilenameValidator $filenameValidator,
  49. ServerVersion $serverVersion,
  50. ) {
  51. parent::__construct($appName, $request);
  52. $this->helper = new JSConfigHelper(
  53. $serverVersion,
  54. $l10nFactory->get('lib'),
  55. $defaults,
  56. $appManager,
  57. $session,
  58. $userSession->getUser(),
  59. $config,
  60. $groupManager,
  61. $iniWrapper,
  62. $urlGenerator,
  63. $capabilitiesManager,
  64. $initialStateService,
  65. $tokenProvider,
  66. $filenameValidator,
  67. );
  68. }
  69. /**
  70. * @NoTwoFactorRequired
  71. */
  72. #[PublicPage]
  73. #[NoCSRFRequired]
  74. #[FrontpageRoute(verb: 'GET', url: '/core/js/oc.js')]
  75. public function getConfig(): DataDisplayResponse {
  76. $data = $this->helper->getConfig();
  77. return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']);
  78. }
  79. }