]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-moderation/video-block.service.ts
Implement two factor in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / video-block.service.ts
index c22ceefcce4d6d5a16a75ba89c3636c2e62a9d81..ab352a2d64ea4c92d68bc2d2c3ea24381dcbe7ed 100644 (file)
@@ -1,9 +1,10 @@
 import { SortMeta } from 'primeng/api'
 import { from as observableFrom, Observable } from 'rxjs'
-import { catchError, concatMap, map, toArray } from 'rxjs/operators'
+import { catchError, concatMap, toArray } from 'rxjs/operators'
 import { HttpClient, HttpParams } from '@angular/common/http'
 import { Injectable } from '@angular/core'
 import { RestExtractor, RestPagination, RestService } from '@app/core'
+import { arrayify } from '@shared/core-utils'
 import { ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models'
 import { environment } from '../../../environments/environment'
 
@@ -46,14 +47,11 @@ export class VideoBlockService {
     if (type) params = params.append('type', type.toString())
 
     return this.authHttp.get<ResultList<VideoBlacklist>>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params })
-               .pipe(
-                 map(res => this.restExtractor.convertResultListDateToHuman(res)),
-                 catchError(res => this.restExtractor.handleError(res))
-               )
+               .pipe(catchError(res => this.restExtractor.handleError(res)))
   }
 
   unblockVideo (videoIdArgs: number | number[]) {
-    const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ]
+    const videoIds = arrayify(videoIdArgs)
 
     return observableFrom(videoIds)
       .pipe(
@@ -63,16 +61,20 @@ export class VideoBlockService {
       )
   }
 
-  blockVideo (videoId: number, reason: string, unfederate: boolean) {
-    const body = {
-      unfederate,
-      reason
-    }
+  blockVideo (options: {
+    videoId: number
+    reason?: string
+    unfederate: boolean
+  }[]) {
+    return observableFrom(options)
+      .pipe(
+        concatMap(({ videoId, unfederate, reason }) => {
+          const body = { unfederate, reason }
 
-    return this.authHttp.post(VideoBlockService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
-               .pipe(
-                 map(this.restExtractor.extractDataBool),
-                 catchError(res => this.restExtractor.handleError(res))
-               )
+          return this.authHttp.post(VideoBlockService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
+        }),
+        toArray(),
+        catchError(res => this.restExtractor.handleError(res))
+      )
   }
 }