You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

appconfig.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author John Molakvoæ <skjnldsv@protonmail.com>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. import $ from 'jquery'
  24. import { generateOcsUrl } from '@nextcloud/router'
  25. import OC from '../OC/index'
  26. /**
  27. * @param {string} method 'post' or 'delete'
  28. * @param {string} endpoint endpoint
  29. * @param {object} [options] destructuring object
  30. * @param {object} [options.data] option data
  31. * @param {Function} [options.success] success callback
  32. * @param {Function} [options.error] error callback
  33. */
  34. function call(method, endpoint, options) {
  35. if ((method === 'post' || method === 'delete') && OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  36. OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(call, this, method, endpoint, options))
  37. return
  38. }
  39. options = options || {}
  40. $.ajax({
  41. type: method.toUpperCase(),
  42. url: generateOcsUrl('apps/provisioning_api/api/v1/config/apps') + endpoint,
  43. data: options.data || {},
  44. success: options.success,
  45. error: options.error,
  46. })
  47. }
  48. /**
  49. * @param {object} [options] destructuring object
  50. * @param {Function} [options.success] success callback
  51. * @since 11.0.0
  52. */
  53. export function getApps(options) {
  54. call('get', '', options)
  55. }
  56. /**
  57. * @param {string} app app id
  58. * @param {object} [options] destructuring object
  59. * @param {Function} [options.success] success callback
  60. * @param {Function} [options.error] error callback
  61. * @since 11.0.0
  62. */
  63. export function getKeys(app, options) {
  64. call('get', '/' + app, options)
  65. }
  66. /**
  67. * @param {string} app app id
  68. * @param {string} key key
  69. * @param {string | Function} defaultValue default value
  70. * @param {object} [options] destructuring object
  71. * @param {Function} [options.success] success callback
  72. * @param {Function} [options.error] error callback
  73. * @since 11.0.0
  74. */
  75. export function getValue(app, key, defaultValue, options) {
  76. options = options || {}
  77. options.data = {
  78. defaultValue,
  79. }
  80. call('get', '/' + app + '/' + key, options)
  81. }
  82. /**
  83. * @param {string} app app id
  84. * @param {string} key key
  85. * @param {string} value value
  86. * @param {object} [options] destructuring object
  87. * @param {Function} [options.success] success callback
  88. * @param {Function} [options.error] error callback
  89. * @since 11.0.0
  90. */
  91. export function setValue(app, key, value, options) {
  92. options = options || {}
  93. options.data = {
  94. value,
  95. }
  96. call('post', '/' + app + '/' + key, options)
  97. }
  98. /**
  99. * @param {string} app app id
  100. * @param {string} key key
  101. * @param {object} [options] destructuring object
  102. * @param {Function} [options.success] success callback
  103. * @param {Function} [options.error] error callback
  104. * @since 11.0.0
  105. */
  106. export function deleteKey(app, key, options) {
  107. call('delete', '/' + app + '/' + key, options)
  108. }