AISettingsController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Settings\Controller;
  8. use OCP\AppFramework\Controller;
  9. use OCP\AppFramework\Http\DataResponse;
  10. use OCP\IConfig;
  11. use OCP\IRequest;
  12. class AISettingsController extends Controller {
  13. /**
  14. * @param string $appName
  15. * @param IRequest $request
  16. * @param IConfig $config
  17. */
  18. public function __construct(
  19. $appName,
  20. IRequest $request,
  21. private IConfig $config,
  22. ) {
  23. parent::__construct($appName, $request);
  24. }
  25. /**
  26. * Sets the email settings
  27. *
  28. * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence)
  29. *
  30. * @param array $settings
  31. * @return DataResponse
  32. */
  33. public function update($settings) {
  34. $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
  35. foreach ($keys as $key) {
  36. if (!isset($settings[$key])) {
  37. continue;
  38. }
  39. $this->config->setAppValue('core', $key, json_encode($settings[$key]));
  40. }
  41. return new DataResponse();
  42. }
  43. }