config.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
  2. import { CustomConfig } from '../../models/server/custom-config.model'
  3. import { DeepPartial } from '@server/typings/utils'
  4. import { merge } from 'lodash'
  5. function getConfig (url: string) {
  6. const path = '/api/v1/config'
  7. return makeGetRequest({
  8. url,
  9. path,
  10. statusCodeExpected: 200
  11. })
  12. }
  13. function getAbout (url: string) {
  14. const path = '/api/v1/config/about'
  15. return makeGetRequest({
  16. url,
  17. path,
  18. statusCodeExpected: 200
  19. })
  20. }
  21. function getCustomConfig (url: string, token: string, statusCodeExpected = 200) {
  22. const path = '/api/v1/config/custom'
  23. return makeGetRequest({
  24. url,
  25. token,
  26. path,
  27. statusCodeExpected
  28. })
  29. }
  30. function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) {
  31. const path = '/api/v1/config/custom'
  32. return makePutBodyRequest({
  33. url,
  34. token,
  35. path,
  36. fields: newCustomConfig,
  37. statusCodeExpected
  38. })
  39. }
  40. function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
  41. const updateParams: CustomConfig = {
  42. instance: {
  43. name: 'PeerTube updated',
  44. shortDescription: 'my short description',
  45. description: 'my super description',
  46. terms: 'my super terms',
  47. codeOfConduct: 'my super coc',
  48. creationReason: 'my super creation reason',
  49. moderationInformation: 'my super moderation information',
  50. administrator: 'Kuja',
  51. maintenanceLifetime: 'forever',
  52. businessModel: 'my super business model',
  53. hardwareInformation: '2vCore 3GB RAM',
  54. languages: [ 'en', 'es' ],
  55. categories: [ 1, 2 ],
  56. defaultClientRoute: '/videos/recently-added',
  57. isNSFW: true,
  58. defaultNSFWPolicy: 'blur',
  59. customizations: {
  60. javascript: 'alert("coucou")',
  61. css: 'body { background-color: red; }'
  62. }
  63. },
  64. theme: {
  65. default: 'default'
  66. },
  67. services: {
  68. twitter: {
  69. username: '@MySuperUsername',
  70. whitelisted: true
  71. }
  72. },
  73. cache: {
  74. previews: {
  75. size: 2
  76. },
  77. captions: {
  78. size: 3
  79. }
  80. },
  81. signup: {
  82. enabled: false,
  83. limit: 5,
  84. requiresEmailVerification: false
  85. },
  86. admin: {
  87. email: 'superadmin1@example.com'
  88. },
  89. contactForm: {
  90. enabled: true
  91. },
  92. user: {
  93. videoQuota: 5242881,
  94. videoQuotaDaily: 318742
  95. },
  96. transcoding: {
  97. enabled: true,
  98. allowAdditionalExtensions: true,
  99. allowAudioFiles: true,
  100. threads: 1,
  101. resolutions: {
  102. '240p': false,
  103. '360p': true,
  104. '480p': true,
  105. '720p': false,
  106. '1080p': false,
  107. '2160p': false
  108. },
  109. webtorrent: {
  110. enabled: true
  111. },
  112. hls: {
  113. enabled: false
  114. }
  115. },
  116. import: {
  117. videos: {
  118. http: {
  119. enabled: false
  120. },
  121. torrent: {
  122. enabled: false
  123. }
  124. }
  125. },
  126. autoBlacklist: {
  127. videos: {
  128. ofUsers: {
  129. enabled: false
  130. }
  131. }
  132. },
  133. followers: {
  134. instance: {
  135. enabled: true,
  136. manualApproval: false
  137. }
  138. },
  139. followings: {
  140. instance: {
  141. autoFollowBack: {
  142. enabled: false
  143. },
  144. autoFollowIndex: {
  145. indexUrl: 'https://instances.joinpeertube.org',
  146. enabled: false
  147. }
  148. }
  149. }
  150. }
  151. merge(updateParams, newConfig)
  152. return updateCustomConfig(url, token, updateParams)
  153. }
  154. function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
  155. const path = '/api/v1/config/custom'
  156. return makeDeleteRequest({
  157. url,
  158. token,
  159. path,
  160. statusCodeExpected
  161. })
  162. }
  163. // ---------------------------------------------------------------------------
  164. export {
  165. getConfig,
  166. getCustomConfig,
  167. updateCustomConfig,
  168. getAbout,
  169. deleteCustomConfig,
  170. updateCustomSubConfig
  171. }