1
0

AISettingsController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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;
  24. use OCP\AppFramework\Http\DataResponse;
  25. use OCP\IConfig;
  26. use OCP\IL10N;
  27. use OCP\IRequest;
  28. use OCP\IURLGenerator;
  29. use OCP\IUserSession;
  30. use OCP\Mail\IMailer;
  31. use function GuzzleHttp\Promise\queue;
  32. class AISettingsController extends Controller {
  33. /**
  34. * @param string $appName
  35. * @param IRequest $request
  36. * @param IConfig $config
  37. */
  38. public function __construct(
  39. $appName,
  40. IRequest $request,
  41. private IConfig $config,
  42. ) {
  43. parent::__construct($appName, $request);
  44. }
  45. /**
  46. * Sets the email settings
  47. *
  48. * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence)
  49. *
  50. * @param array $settings
  51. * @return DataResponse
  52. */
  53. public function update($settings) {
  54. $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.translation_provider_preferences'];
  55. foreach ($keys as $key) {
  56. if (!isset($settings[$key])) {
  57. continue;
  58. }
  59. $this->config->setAppValue('core', $key, json_encode($settings[$key]));
  60. }
  61. return new DataResponse();
  62. }
  63. }