1
0

OCJSController.php 2.0 KB

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