2
1

config.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
  2. import { CustomConfig } from '../../models/server/custom-config.model'
  3. import { DeepPartial, HttpStatusCode } from '@shared/core-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: HttpStatusCode.OK_200
  11. })
  12. }
  13. function getAbout (url: string) {
  14. const path = '/api/v1/config/about'
  15. return makeGetRequest({
  16. url,
  17. path,
  18. statusCodeExpected: HttpStatusCode.OK_200
  19. })
  20. }
  21. function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_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 = HttpStatusCode.OK_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. '0p': false,
  103. '240p': false,
  104. '360p': true,
  105. '480p': true,
  106. '720p': false,
  107. '1080p': false,
  108. '1440p': false,
  109. '2160p': false
  110. },
  111. webtorrent: {
  112. enabled: true
  113. },
  114. hls: {
  115. enabled: false
  116. }
  117. },
  118. live: {
  119. enabled: true,
  120. allowReplay: false,
  121. maxDuration: -1,
  122. maxInstanceLives: -1,
  123. maxUserLives: 50,
  124. transcoding: {
  125. enabled: true,
  126. threads: 4,
  127. resolutions: {
  128. '240p': true,
  129. '360p': true,
  130. '480p': true,
  131. '720p': true,
  132. '1080p': true,
  133. '1440p': true,
  134. '2160p': true
  135. }
  136. }
  137. },
  138. import: {
  139. videos: {
  140. http: {
  141. enabled: false
  142. },
  143. torrent: {
  144. enabled: false
  145. }
  146. }
  147. },
  148. autoBlacklist: {
  149. videos: {
  150. ofUsers: {
  151. enabled: false
  152. }
  153. }
  154. },
  155. followers: {
  156. instance: {
  157. enabled: true,
  158. manualApproval: false
  159. }
  160. },
  161. followings: {
  162. instance: {
  163. autoFollowBack: {
  164. enabled: false
  165. },
  166. autoFollowIndex: {
  167. indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
  168. enabled: false
  169. }
  170. }
  171. },
  172. broadcastMessage: {
  173. enabled: true,
  174. level: 'warning',
  175. message: 'hello',
  176. dismissable: true
  177. },
  178. search: {
  179. remoteUri: {
  180. users: true,
  181. anonymous: true
  182. },
  183. searchIndex: {
  184. enabled: true,
  185. url: 'https://search.joinpeertube.org',
  186. disableLocalSearch: true,
  187. isDefaultSearch: true
  188. }
  189. }
  190. }
  191. merge(updateParams, newConfig)
  192. return updateCustomConfig(url, token, updateParams)
  193. }
  194. function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
  195. const path = '/api/v1/config/custom'
  196. return makeDeleteRequest({
  197. url,
  198. token,
  199. path,
  200. statusCodeExpected
  201. })
  202. }
  203. // ---------------------------------------------------------------------------
  204. export {
  205. getConfig,
  206. getCustomConfig,
  207. updateCustomConfig,
  208. getAbout,
  209. deleteCustomConfig,
  210. updateCustomSubConfig
  211. }