1
0

AISettingsController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
  5. *
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\Settings\Controller;
  22. use OCP\AppFramework\Controller;
  23. use OCP\AppFramework\Http\DataResponse;
  24. use OCP\IConfig;
  25. use OCP\IRequest;
  26. class AISettingsController extends Controller {
  27. /**
  28. * @param string $appName
  29. * @param IRequest $request
  30. * @param IConfig $config
  31. */
  32. public function __construct(
  33. $appName,
  34. IRequest $request,
  35. private IConfig $config,
  36. ) {
  37. parent::__construct($appName, $request);
  38. }
  39. /**
  40. * Sets the email settings
  41. *
  42. * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence)
  43. *
  44. * @param array $settings
  45. * @return DataResponse
  46. */
  47. public function update($settings) {
  48. $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
  49. foreach ($keys as $key) {
  50. if (!isset($settings[$key])) {
  51. continue;
  52. }
  53. $this->config->setAppValue('core', $key, json_encode($settings[$key]));
  54. }
  55. return new DataResponse();
  56. }
  57. }