OCJSController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Template\JSConfigHelper;
  11. use OCP\App\IAppManager;
  12. use OCP\AppFramework\Controller;
  13. use OCP\AppFramework\Http;
  14. use OCP\AppFramework\Http\Attribute\FrontpageRoute;
  15. use OCP\AppFramework\Http\Attribute\OpenAPI;
  16. use OCP\AppFramework\Http\DataDisplayResponse;
  17. use OCP\Defaults;
  18. use OCP\IConfig;
  19. use OCP\IGroupManager;
  20. use OCP\IInitialStateService;
  21. use OCP\IRequest;
  22. use OCP\ISession;
  23. use OCP\IURLGenerator;
  24. use OCP\IUserSession;
  25. use OCP\L10N\IFactory;
  26. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  27. class OCJSController extends Controller {
  28. private JSConfigHelper $helper;
  29. public function __construct(
  30. string $appName,
  31. IRequest $request,
  32. IFactory $l10nFactory,
  33. Defaults $defaults,
  34. IAppManager $appManager,
  35. ISession $session,
  36. IUserSession $userSession,
  37. IConfig $config,
  38. IGroupManager $groupManager,
  39. IniGetWrapper $iniWrapper,
  40. IURLGenerator $urlGenerator,
  41. CapabilitiesManager $capabilitiesManager,
  42. IInitialStateService $initialStateService,
  43. IProvider $tokenProvider,
  44. ) {
  45. parent::__construct($appName, $request);
  46. $this->helper = new JSConfigHelper(
  47. $l10nFactory->get('lib'),
  48. $defaults,
  49. $appManager,
  50. $session,
  51. $userSession->getUser(),
  52. $config,
  53. $groupManager,
  54. $iniWrapper,
  55. $urlGenerator,
  56. $capabilitiesManager,
  57. $initialStateService,
  58. $tokenProvider
  59. );
  60. }
  61. /**
  62. * @NoCSRFRequired
  63. * @NoTwoFactorRequired
  64. * @PublicPage
  65. */
  66. #[FrontpageRoute(verb: 'GET', url: '/core/js/oc.js')]
  67. public function getConfig(): DataDisplayResponse {
  68. $data = $this->helper->getConfig();
  69. return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']);
  70. }
  71. }