]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video/video.service.ts
Replace current state when changing page
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.service.ts
index 0091554101abf2a8b22b2c20c2ff9c48f734e53e..ef8babd55a9ac9fc0ada06666967b4e76529cc59 100644 (file)
@@ -16,7 +16,7 @@ import { ComponentPagination } from '../rest/component-pagination.model'
 import { RestExtractor } from '../rest/rest-extractor.service'
 import { RestService } from '../rest/rest.service'
 import { UserService } from '../users/user.service'
-import { SortField } from './sort-field.type'
+import { VideoSortField } from './sort-field.type'
 import { VideoDetails } from './video-details.model'
 import { VideoEdit } from './video-edit.model'
 import { Video } from './video.model'
@@ -86,7 +86,7 @@ export class VideoService {
       .catch(this.restExtractor.handleError)
   }
 
-  getMyVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+  getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<{ videos: Video[], totalVideos: number}> {
     const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
 
     let params = new HttpParams()
@@ -99,7 +99,7 @@ export class VideoService {
 
   getVideos (
     videoPagination: ComponentPagination,
-    sort: SortField,
+    sort: VideoSortField,
     filter?: VideoFilter
   ): Observable<{ videos: Video[], totalVideos: number}> {
     const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
@@ -117,51 +117,50 @@ export class VideoService {
       .catch((res) => this.restExtractor.handleError(res))
   }
 
-  baseFeed () {
-    const feed = {}
-
-    for (let item in FeedFormat) {
-      feed[FeedFormat[item]] = VideoService.BASE_FEEDS_URL + item.toLowerCase()
+  buildBaseFeedUrls (params: HttpParams) {
+    const feeds = [
+      {
+        label: 'rss 2.0',
+        url: VideoService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
+      },
+      {
+        label: 'atom 1.0',
+        url: VideoService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
+      },
+      {
+        label: 'json 1.0',
+        url: VideoService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
+      }
+    ]
+
+    if (params && params.keys().length !== 0) {
+      for (const feed of feeds) {
+        feed.url += '?' + params.toString()
+      }
     }
 
-    return feed
+    return feeds
   }
 
-  getFeed (
-    filter?: VideoFilter
-  ) {
-    let params = this.restService.addRestGetParams(new HttpParams())
-    const feed = this.baseFeed()
+  getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) {
+    let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
 
-    if (filter) {
-      params = params.set('filter', filter)
-    }
-    for (let item in feed) {
-      feed[item] = feed[item] + ((params.toString().length === 0) ? '' : '?') + params.toString()
-    }
+    if (filter) params = params.set('filter', filter)
 
-    return feed
+    return this.buildBaseFeedUrls(params)
   }
 
-  getAccountFeed (
-    accountId: number,
-    host?: string
-  ) {
+  getAccountFeedUrls (accountId: number) {
     let params = this.restService.addRestGetParams(new HttpParams())
-    const feed = this.baseFeed()
-
     params = params.set('accountId', accountId.toString())
-    for (let item in feed) {
-      feed[item] = feed[item] + ((params.toString().length === 0) ? '' : '?') + params.toString()
-    }
 
-    return feed
+    return this.buildBaseFeedUrls(params)
   }
 
   searchVideos (
     search: string,
     videoPagination: ComponentPagination,
-    sort: SortField
+    sort: VideoSortField
   ): Observable<{ videos: Video[], totalVideos: number}> {
     const url = VideoService.BASE_VIDEO_URL + 'search'