]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-search/find-in-bulk.service.ts
Update angular
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-search / find-in-bulk.service.ts
index 30cddc1544deee75cc7919c9ae9132625e3a2dc2..125d5e2b868c5537509d7f63b9abb1dd5bbfb364 100644 (file)
@@ -7,8 +7,9 @@ import { ResultList } from '@shared/models/common'
 import { Video, VideoChannel } from '../shared-main'
 import { VideoPlaylist } from '../shared-video-playlist'
 import { SearchService } from './search.service'
+import { AdvancedSearch } from './advanced-search.model'
 
-const logger = debug('peertube:search:FindInBulkService')
+const debugLogger = debug('peertube:search:FindInBulkService')
 
 type BulkObservables <P extends number | string, R> = {
   notifier: Subject<P>
@@ -18,6 +19,8 @@ type BulkObservables <P extends number | string, R> = {
 @Injectable()
 export class FindInBulkService {
 
+  private advancedSearchForBulk: AdvancedSearch
+
   private getVideoInBulk: BulkObservables<string, ResultList<Video>>
   private getChannelInBulk: BulkObservables<string, ResultList<VideoChannel>>
   private getPlaylistInBulk: BulkObservables<string, ResultList<VideoPlaylist>>
@@ -28,20 +31,22 @@ export class FindInBulkService {
     this.getVideoInBulk = this.buildBulkObservableObject(this.getVideosInBulk.bind(this))
     this.getChannelInBulk = this.buildBulkObservableObject(this.getChannelsInBulk.bind(this))
     this.getPlaylistInBulk = this.buildBulkObservableObject(this.getPlaylistsInBulk.bind(this))
+
+    this.advancedSearchForBulk = new AdvancedSearch({ searchTarget: 'local' })
   }
 
   getVideo (uuid: string): Observable<Video> {
-    logger('Schedule video fetch for uuid %s.', uuid)
+    debugLogger('Schedule video fetch for uuid %s.', uuid)
 
     return this.getData({
       observableObject: this.getVideoInBulk,
-      finder: v => v.uuid === uuid,
+      finder: v => v.uuid === uuid || v.shortUUID === uuid,
       param: uuid
     })
   }
 
   getChannel (handle: string): Observable<VideoChannel> {
-    logger('Schedule channel fetch for handle %s.', handle)
+    debugLogger('Schedule channel fetch for handle %s.', handle)
 
     return this.getData({
       observableObject: this.getChannelInBulk,
@@ -51,7 +56,7 @@ export class FindInBulkService {
   }
 
   getPlaylist (uuid: string): Observable<VideoPlaylist> {
-    logger('Schedule playlist fetch for uuid %s.', uuid)
+    debugLogger('Schedule playlist fetch for uuid %s.', uuid)
 
     return this.getData({
       observableObject: this.getPlaylistInBulk,
@@ -75,13 +80,18 @@ export class FindInBulkService {
           map(result => result.response.data),
           map(data => data.find(finder))
         )
-        .subscribe(result => {
-          if (!result) {
-            obs.error(new Error($localize`Element ${param} not found`))
-          } else {
+        .subscribe({
+          next: result => {
+            if (!result) {
+              obs.error(new Error($localize`Element ${param} not found`))
+              return
+            }
+
             obs.next(result)
             obs.complete()
-          }
+          },
+
+          error: err => obs.error(err)
         })
 
       observableObject.notifier.next(param)
@@ -89,21 +99,33 @@ export class FindInBulkService {
   }
 
   private getVideosInBulk (uuids: string[]) {
-    logger('Fetching videos %s.', uuids.join(', '))
+    debugLogger('Fetching videos %s.', uuids.join(', '))
 
-    return this.searchService.searchVideos({ uuids })
+    return this.searchService.searchVideos({
+      uuids,
+      componentPagination: { itemsPerPage: uuids.length, currentPage: 1 },
+      advancedSearch: this.advancedSearchForBulk
+    })
   }
 
   private getChannelsInBulk (handles: string[]) {
-    logger('Fetching channels %s.', handles.join(', '))
+    debugLogger('Fetching channels %s.', handles.join(', '))
 
-    return this.searchService.searchVideoChannels({ handles })
+    return this.searchService.searchVideoChannels({
+      handles,
+      componentPagination: { itemsPerPage: handles.length, currentPage: 1 },
+      advancedSearch: this.advancedSearchForBulk
+    })
   }
 
   private getPlaylistsInBulk (uuids: string[]) {
-    logger('Fetching playlists %s.', uuids.join(', '))
+    debugLogger('Fetching playlists %s.', uuids.join(', '))
 
-    return this.searchService.searchVideoPlaylists({ uuids })
+    return this.searchService.searchVideoPlaylists({
+      uuids,
+      componentPagination: { itemsPerPage: uuids.length, currentPage: 1 },
+      advancedSearch: this.advancedSearchForBulk
+    })
   }
 
   private buildBulkObservableObject <P extends number | string, R> (bulkGet: (params: P[]) => Observable<R>) {