X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Fvideo%2Fvideo.service.ts;h=70be5d7d29e06ae2b9ead2ee6864d11a5a6c59a8;hb=5beb89f223539f1e415a976ff104f772526b4d20;hp=ee3549695f46bc52007d6f3a309d8eb4ff074ed9;hpb=2d011d94aa4086af3a87e254552062599d8c50bd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index ee3549695..70be5d7d2 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts @@ -1,11 +1,9 @@ -import { FfprobeData } from 'fluent-ffmpeg' import { Observable } from 'rxjs' import { catchError, map, switchMap } from 'rxjs/operators' import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' import { Injectable } from '@angular/core' -import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' +import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService, AuthService } from '@app/core' import { objectToFormData } from '@app/helpers' -import { I18n } from '@ngx-translate/i18n-polyfill' import { FeedFormat, NSFWPolicyType, @@ -16,13 +14,15 @@ import { Video as VideoServerModel, VideoConstant, VideoDetails as VideoDetailsServerModel, + VideoFileMetadata, VideoFilter, VideoPrivacy, VideoSortField, VideoUpdate } from '@shared/models' import { environment } from '../../../../environments/environment' -import { Account, AccountService } from '../account' +import { Account } from '../account/account.model' +import { AccountService } from '../account/account.service' import { VideoChannel, VideoChannelService } from '../video-channel' import { VideoDetails } from './video-details.model' import { VideoEdit } from './video-edit.model' @@ -43,13 +43,13 @@ export interface VideosProvider { export class VideoService implements VideosProvider { static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' static BASE_FEEDS_URL = environment.apiUrl + '/feeds/videos.' + static BASE_SUBSCRIPTION_FEEDS_URL = environment.apiUrl + '/feeds/subscriptions.' constructor ( private authHttp: HttpClient, private restExtractor: RestExtractor, private restService: RestService, - private serverService: ServerService, - private i18n: I18n + private serverService: ServerService ) {} getVideoViewUrl (uuid: string) { @@ -97,6 +97,7 @@ export class VideoService implements VideosProvider { downloadEnabled: video.downloadEnabled, thumbnailfile: video.thumbnailfile, previewfile: video.previewfile, + pluginData: video.pluginData, scheduleUpdate, originallyPublishedAt } @@ -133,16 +134,28 @@ export class VideoService implements VideosProvider { ) } - getAccountVideos ( + getAccountVideos (parameters: { account: Account, videoPagination: ComponentPaginationLight, sort: VideoSortField - ): Observable> { + nsfwPolicy?: NSFWPolicyType + videoFilter?: VideoFilter + }): Observable> { + const { account, videoPagination, sort, videoFilter, nsfwPolicy } = parameters + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) + if (nsfwPolicy) { + params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) + } + + if (videoFilter) { + params = params.set('filter', videoFilter) + } + return this.authHttp .get>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params }) .pipe( @@ -151,12 +164,15 @@ export class VideoService implements VideosProvider { ) } - getVideoChannelVideos ( + getVideoChannelVideos (parameters: { videoChannel: VideoChannel, videoPagination: ComponentPaginationLight, sort: VideoSortField, nsfwPolicy?: NSFWPolicyType - ): Observable> { + videoFilter?: VideoFilter + }): Observable> { + const { videoChannel, videoPagination, sort, nsfwPolicy, videoFilter } = parameters + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -166,6 +182,10 @@ export class VideoService implements VideosProvider { params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) } + if (videoFilter) { + params = params.set('filter', videoFilter) + } + return this.authHttp .get>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost + '/videos', { params }) .pipe( @@ -217,22 +237,22 @@ export class VideoService implements VideosProvider { ) } - buildBaseFeedUrls (params: HttpParams) { + buildBaseFeedUrls (params: HttpParams, base = VideoService.BASE_FEEDS_URL) { const feeds = [ { format: FeedFormat.RSS, label: 'media rss 2.0', - url: VideoService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase() + url: base + FeedFormat.RSS.toLowerCase() }, { format: FeedFormat.ATOM, label: 'atom 1.0', - url: VideoService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase() + url: base + FeedFormat.ATOM.toLowerCase() }, { format: FeedFormat.JSON, label: 'json 1.0', - url: VideoService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase() + url: base + FeedFormat.JSON.toLowerCase() } ] @@ -273,9 +293,17 @@ export class VideoService implements VideosProvider { return this.buildBaseFeedUrls(params) } + getVideoSubscriptionFeedUrls (accountId: number, feedToken: string) { + let params = this.restService.addRestGetParams(new HttpParams()) + params = params.set('accountId', accountId.toString()) + params = params.set('token', feedToken) + + return this.buildBaseFeedUrls(params, VideoService.BASE_SUBSCRIPTION_FEEDS_URL) + } + getVideoFileMetadata (metadataUrl: string) { return this.authHttp - .get(metadataUrl) + .get(metadataUrl) .pipe( catchError(err => this.restExtractor.handleError(err)) ) @@ -339,23 +367,25 @@ export class VideoService implements VideosProvider { const base = [ { id: VideoPrivacy.PRIVATE, - label: this.i18n('Only I can see this video') + description: $localize`Only I can see this video` }, { id: VideoPrivacy.UNLISTED, - label: this.i18n('Only people with the private link can see this video') + description: $localize`Only shareable via a private link` }, { id: VideoPrivacy.PUBLIC, - label: this.i18n('Anyone can see this video') + description: $localize`Anyone can see this video` }, { id: VideoPrivacy.INTERNAL, - label: this.i18n('Only users of this instance can see this video') + description: $localize`Only users of this instance can see this video` } ] - return base.filter(o => !!privacies.find(p => p.id === o.id)) + return base + .filter(o => !!privacies.find(p => p.id === o.id)) // filter down to privacies that where in the input + .map(o => ({ ...privacies[o.id - 1], ...o })) // merge the input privacies that contain a label, and extend them with a description } nsfwPolicyToParam (nsfwPolicy: NSFWPolicyType) {