1
0

OCJSController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  30. class OCJSController extends Controller {
  31. private JSConfigHelper $helper;
  32. public function __construct(
  33. string $appName,
  34. IRequest $request,
  35. IFactory $l10nFactory,
  36. Defaults $defaults,
  37. IAppManager $appManager,
  38. ISession $session,
  39. IUserSession $userSession,
  40. IConfig $config,
  41. IGroupManager $groupManager,
  42. IniGetWrapper $iniWrapper,
  43. IURLGenerator $urlGenerator,
  44. CapabilitiesManager $capabilitiesManager,
  45. IInitialStateService $initialStateService,
  46. IProvider $tokenProvider,
  47. FilenameValidator $filenameValidator,
  48. ) {
  49. parent::__construct($appName, $request);
  50. $this->helper = new JSConfigHelper(
  51. $l10nFactory->get('lib'),
  52. $defaults,
  53. $appManager,
  54. $session,
  55. $userSession->getUser(),
  56. $config,
  57. $groupManager,
  58. $iniWrapper,
  59. $urlGenerator,
  60. $capabilitiesManager,
  61. $initialStateService,
  62. $tokenProvider,
  63. $filenameValidator,
  64. );
  65. }
  66. /**
  67. * @NoTwoFactorRequired
  68. */
  69. #[PublicPage]
  70. #[NoCSRFRequired]
  71. #[FrontpageRoute(verb: 'GET', url: '/core/js/oc.js')]
  72. public function getConfig(): DataDisplayResponse {
  73. $data = $this->helper->getConfig();
  74. return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']);
  75. }
  76. }