video-admin.service.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { Observable } from 'rxjs'
  2. import { catchError, switchMap } from 'rxjs/operators'
  3. import { HttpClient, HttpParams } from '@angular/common/http'
  4. import { Injectable } from '@angular/core'
  5. import { RestExtractor, RestPagination, RestService } from '@app/core'
  6. import { AdvancedInputFilter } from '@app/shared/shared-forms'
  7. import { CommonVideoParams, Video, VideoService } from '@app/shared/shared-main'
  8. import { ResultList, VideoInclude, VideoPrivacy } from '@peertube/peertube-models'
  9. import { getAllPrivacies } from '@peertube/peertube-core-utils'
  10. @Injectable()
  11. export class VideoAdminService {
  12. constructor (
  13. private videoService: VideoService,
  14. private authHttp: HttpClient,
  15. private restExtractor: RestExtractor,
  16. private restService: RestService
  17. ) {}
  18. getAdminVideos (
  19. options: CommonVideoParams & { pagination: RestPagination, search?: string }
  20. ): Observable<ResultList<Video>> {
  21. const { pagination, search } = options
  22. let params = new HttpParams()
  23. params = this.videoService.buildCommonVideosParams({ params, ...options })
  24. params = params.set('start', pagination.start.toString())
  25. .set('count', pagination.count.toString())
  26. params = this.buildAdminParamsFromSearch(search, params)
  27. return this.authHttp
  28. .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
  29. .pipe(
  30. switchMap(res => this.videoService.extractVideos(res)),
  31. catchError(err => this.restExtractor.handleError(err))
  32. )
  33. }
  34. buildAdminInputFilter (): AdvancedInputFilter[] {
  35. return [
  36. {
  37. title: $localize`Video type`,
  38. children: [
  39. {
  40. value: 'isLive:false',
  41. label: $localize`VOD`
  42. },
  43. {
  44. value: 'isLive:true',
  45. label: $localize`Live`
  46. }
  47. ]
  48. },
  49. {
  50. title: $localize`Video files`,
  51. children: [
  52. {
  53. value: 'webVideos:true isLocal:true',
  54. label: $localize`With Web Videos`
  55. },
  56. {
  57. value: 'webVideos:false isLocal:true',
  58. label: $localize`Without Web Videos`
  59. },
  60. {
  61. value: 'hls:true isLocal:true',
  62. label: $localize`With HLS`
  63. },
  64. {
  65. value: 'hls:false isLocal:true',
  66. label: $localize`Without HLS`
  67. }
  68. ]
  69. },
  70. {
  71. title: $localize`Videos scope`,
  72. children: [
  73. {
  74. value: 'isLocal:false',
  75. label: $localize`Remote videos`
  76. },
  77. {
  78. value: 'isLocal:true',
  79. label: $localize`Local videos`
  80. }
  81. ]
  82. },
  83. {
  84. title: $localize`Exclude`,
  85. children: [
  86. {
  87. value: 'excludeMuted',
  88. label: $localize`Exclude muted accounts`
  89. },
  90. {
  91. value: 'excludePublic',
  92. label: $localize`Exclude public videos`
  93. }
  94. ]
  95. }
  96. ]
  97. }
  98. private buildAdminParamsFromSearch (search: string, params: HttpParams) {
  99. let include = VideoInclude.BLACKLISTED |
  100. VideoInclude.BLOCKED_OWNER |
  101. VideoInclude.NOT_PUBLISHED_STATE |
  102. VideoInclude.FILES
  103. let privacyOneOf = getAllPrivacies()
  104. if (!search) return this.restService.addObjectParams(params, { include, privacyOneOf })
  105. const filters = this.restService.parseQueryStringFilter(search, {
  106. isLocal: {
  107. prefix: 'isLocal:',
  108. isBoolean: true
  109. },
  110. hasHLSFiles: {
  111. prefix: 'hls:',
  112. isBoolean: true
  113. },
  114. hasWebVideoFiles: {
  115. prefix: 'webVideos:',
  116. isBoolean: true
  117. },
  118. isLive: {
  119. prefix: 'isLive:',
  120. isBoolean: true
  121. },
  122. excludeMuted: {
  123. prefix: 'excludeMuted',
  124. handler: () => true
  125. },
  126. excludePublic: {
  127. prefix: 'excludePublic',
  128. handler: () => true
  129. }
  130. })
  131. if (filters.excludeMuted) {
  132. include &= ~VideoInclude.BLOCKED_OWNER
  133. filters.excludeMuted = undefined
  134. }
  135. if (filters.excludePublic) {
  136. privacyOneOf = [ VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.INTERNAL, VideoPrivacy.PASSWORD_PROTECTED ]
  137. filters.excludePublic = undefined
  138. }
  139. return this.restService.addObjectParams(params, { ...filters, include, privacyOneOf })
  140. }
  141. }