1
0
Fork 0
peertube/client/src/app/videos/+video-watch/video-watch.component.ts

355 lines
10 KiB
TypeScript
Raw Normal View History

2017-10-09 12:28:44 +00:00
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { Observable } from 'rxjs/Observable'
import { Subscription } from 'rxjs/Subscription'
2017-07-06 12:39:39 +00:00
import videojs from 'video.js'
import '../../../assets/player/peertube-videojs-plugin'
2017-07-06 15:43:58 +00:00
import { MetaService } from '@ngx-meta/core'
import { NotificationsService } from 'angular2-notifications'
import { AuthService, ConfirmService } from '../../core'
import { VideoDownloadComponent } from './video-download.component'
import { VideoShareComponent } from './video-share.component'
import { VideoReportComponent } from './video-report.component'
import { VideoDetails, VideoService, MarkdownService } from '../shared'
2017-10-10 08:02:18 +00:00
import { VideoBlacklistService } from '../../shared'
import { UserVideoRateType, VideoRateType } from '../../../../../shared'
2016-03-14 12:50:19 +00:00
@Component({
selector: 'my-video-watch',
templateUrl: './video-watch.component.html',
styleUrls: [ './video-watch.component.scss' ]
2016-03-14 12:50:19 +00:00
})
2016-07-08 15:15:14 +00:00
export class VideoWatchComponent implements OnInit, OnDestroy {
@ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
@ViewChild('videoShareModal') videoShareModal: VideoShareComponent
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
downloadSpeed: number
error = false
loading = false
numPeers: number
player: videojs.Player
2017-07-11 08:09:18 +00:00
playerElement: HTMLMediaElement
uploadSpeed: number
2017-06-17 09:28:11 +00:00
userRating: UserVideoRateType = null
2017-10-25 14:43:19 +00:00
video: VideoDetails = null
2017-10-19 13:39:08 +00:00
videoPlayerLoaded = false
2017-10-19 13:47:56 +00:00
videoNotFound = false
completeDescriptionShown = false
completeVideoDescription: string
shortVideoDescription: string
videoHTMLDescription = ''
private paramsSub: Subscription
constructor (
2016-05-27 15:49:18 +00:00
private elementRef: ElementRef,
2016-07-08 15:15:14 +00:00
private route: ActivatedRoute,
2017-04-04 19:37:03 +00:00
private router: Router,
2016-05-31 20:39:36 +00:00
private videoService: VideoService,
2017-10-10 08:02:18 +00:00
private videoBlacklistService: VideoBlacklistService,
2017-04-04 19:37:03 +00:00
private confirmService: ConfirmService,
2016-11-04 16:37:44 +00:00
private metaService: MetaService,
private authService: AuthService,
private notificationsService: NotificationsService,
private markdownService: MarkdownService
2016-05-31 20:39:36 +00:00
) {}
2016-03-14 12:50:19 +00:00
ngOnInit () {
this.paramsSub = this.route.params.subscribe(routeParams => {
let uuid = routeParams['uuid']
this.videoService.getVideo(uuid).subscribe(
2017-04-04 19:37:03 +00:00
video => this.onVideoFetched(video),
2017-10-19 13:47:56 +00:00
error => {
this.videoNotFound = true
console.error(error)
}
)
})
}
ngOnDestroy () {
// Remove player if it exists
2017-10-19 13:39:08 +00:00
if (this.videoPlayerLoaded === true) {
videojs(this.playerElement).dispose()
}
2016-11-08 20:17:17 +00:00
// Unsubscribe subscriptions
this.paramsSub.unsubscribe()
2016-03-14 12:50:19 +00:00
}
2016-03-14 21:16:43 +00:00
setLike () {
if (this.isUserLoggedIn() === false) return
2017-03-08 20:35:43 +00:00
// Already liked this video
if (this.userRating === 'like') return
2017-03-08 20:35:43 +00:00
this.videoService.setVideoLike(this.video.id)
.subscribe(
() => {
// Update the video like attribute
this.updateVideoRating(this.userRating, 'like')
this.userRating = 'like'
2017-03-08 20:35:43 +00:00
},
err => this.notificationsService.error('Error', err.message)
)
2017-03-08 20:35:43 +00:00
}
setDislike () {
if (this.isUserLoggedIn() === false) return
2017-03-08 20:35:43 +00:00
// Already disliked this video
if (this.userRating === 'dislike') return
2017-03-08 20:35:43 +00:00
this.videoService.setVideoDislike(this.video.id)
.subscribe(
() => {
// Update the video dislike attribute
this.updateVideoRating(this.userRating, 'dislike')
this.userRating = 'dislike'
2017-03-08 20:35:43 +00:00
},
err => this.notificationsService.error('Error', err.message)
)
2017-03-08 20:35:43 +00:00
}
removeVideo (event: Event) {
event.preventDefault()
2017-04-26 19:42:36 +00:00
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
this.confirmService.confirm('Do you really want to delete this video?', 'Delete').subscribe(
res => {
if (res === false) return
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
this.videoService.removeVideo(this.video.id)
2017-04-26 19:42:36 +00:00
.subscribe(
status => {
this.notificationsService.success('Success', `Video ${this.video.name} deleted.`)
2017-04-26 19:42:36 +00:00
// Go back to the video-list.
this.router.navigate(['/videos/list'])
2017-04-26 19:42:36 +00:00
},
error => this.notificationsService.error('Error', error.text)
)
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
)
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
blacklistVideo (event: Event) {
event.preventDefault()
2017-04-26 19:42:36 +00:00
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
this.confirmService.confirm('Do you really want to blacklist this video ?', 'Blacklist').subscribe(
res => {
if (res === false) return
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
2017-10-10 08:02:18 +00:00
this.videoBlacklistService.blacklistVideo(this.video.id)
.subscribe(
status => {
this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`)
this.router.navigate(['/videos/list'])
},
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
2017-10-10 08:02:18 +00:00
error => this.notificationsService.error('Error', error.text)
)
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
)
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
showMoreDescription () {
this.completeDescriptionShown = true
if (this.completeVideoDescription === undefined) {
return this.loadCompleteDescription()
}
this.updateVideoDescription(this.completeVideoDescription)
}
showLessDescription () {
this.completeDescriptionShown = false
this.updateVideoDescription(this.shortVideoDescription)
}
loadCompleteDescription () {
this.videoService.loadCompleteDescription(this.video.descriptionPath)
.subscribe(
description => {
this.shortVideoDescription = this.video.description
this.completeVideoDescription = description
this.updateVideoDescription(this.completeVideoDescription)
},
error => this.notificationsService.error('Error', error.text)
)
}
showReportModal (event: Event) {
event.preventDefault()
this.videoReportModal.show()
2017-01-20 18:22:15 +00:00
}
showShareModal () {
this.videoShareModal.show()
2016-11-08 20:11:57 +00:00
}
showDownloadModal (event: Event) {
event.preventDefault()
this.videoDownloadModal.show()
2016-11-08 20:11:57 +00:00
}
isUserLoggedIn () {
return this.authService.isLoggedIn()
2017-01-20 18:22:15 +00:00
}
canUserUpdateVideo () {
return this.video.isUpdatableBy(this.authService.getUser())
}
isVideoRemovable () {
return this.video.isRemovableBy(this.authService.getUser())
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
isVideoBlacklistable () {
return this.video.isBlackistableBy(this.authService.getUser())
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
private updateVideoDescription (description: string) {
this.video.description = description
this.setVideoDescriptionHTML()
}
private setVideoDescriptionHTML () {
this.videoHTMLDescription = this.markdownService.markdownToHTML(this.video.description)
}
2017-07-23 09:07:30 +00:00
private handleError (err: any) {
const errorMessage: string = typeof err === 'string' ? err : err.message
let message = ''
if (errorMessage.indexOf('http error') !== -1) {
message = 'Cannot fetch video from server, maybe down.'
} else {
message = errorMessage
}
this.notificationsService.error('Error', message)
}
private checkUserRating () {
2017-03-08 20:35:43 +00:00
// Unlogged users do not have ratings
if (this.isUserLoggedIn() === false) return
2017-03-08 20:35:43 +00:00
this.videoService.getUserVideoRating(this.video.id)
.subscribe(
2017-06-20 18:20:09 +00:00
ratingObject => {
2017-03-08 20:35:43 +00:00
if (ratingObject) {
this.userRating = ratingObject.rating
2017-03-08 20:35:43 +00:00
}
},
err => this.notificationsService.error('Error', err.message)
)
2017-03-08 20:35:43 +00:00
}
2017-10-25 14:43:19 +00:00
private onVideoFetched (video: VideoDetails) {
this.video = video
2017-04-04 19:37:03 +00:00
let observable
2017-04-04 19:37:03 +00:00
if (this.video.isVideoNSFWForUser(this.authService.getUser())) {
observable = this.confirmService.confirm(
'This video contains mature or explicit content. Are you sure you want to watch it?',
'Mature or explicit content'
)
2017-04-04 19:37:03 +00:00
} else {
observable = Observable.of(true)
2017-04-04 19:37:03 +00:00
}
observable.subscribe(
res => {
if (res === false) {
2017-10-19 13:39:08 +00:00
return this.router.navigate([ '/videos/list' ])
2017-04-04 19:37:03 +00:00
}
this.playerElement = this.elementRef.nativeElement.querySelector('#video-container')
const videojsOptions = {
controls: true,
autoplay: true,
plugins: {
peertube: {
videoFiles: this.video.files,
playerElement: this.playerElement,
autoplay: true,
peerTubeLink: false
}
}
}
2017-10-19 13:39:08 +00:00
this.videoPlayerLoaded = true
const self = this
videojs(this.playerElement, videojsOptions, function () {
self.player = this
this.on('customError', (event, data) => {
self.handleError(data.err)
})
this.on('torrentInfo', (event, data) => {
self.downloadSpeed = data.downloadSpeed
self.numPeers = data.numPeers
self.uploadSpeed = data.uploadSpeed
})
})
this.setVideoDescriptionHTML()
this.setOpenGraphTags()
this.checkUserRating()
2017-04-04 19:37:03 +00:00
}
)
2017-04-04 19:37:03 +00:00
}
2017-06-17 09:28:11 +00:00
private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) {
let likesToIncrement = 0
let dislikesToIncrement = 0
2017-03-08 20:35:43 +00:00
if (oldRating) {
if (oldRating === 'like') likesToIncrement--
if (oldRating === 'dislike') dislikesToIncrement--
2017-03-08 20:35:43 +00:00
}
if (newRating === 'like') likesToIncrement++
if (newRating === 'dislike') dislikesToIncrement++
2017-03-08 20:35:43 +00:00
this.video.likes += likesToIncrement
this.video.dislikes += dislikesToIncrement
2017-03-08 20:35:43 +00:00
}
private setOpenGraphTags () {
this.metaService.setTitle(this.video.name)
2017-03-10 09:33:36 +00:00
this.metaService.setTag('og:type', 'video')
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:title', this.video.name)
this.metaService.setTag('name', this.video.name)
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:description', this.video.description)
this.metaService.setTag('description', this.video.description)
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:image', this.video.previewPath)
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:duration', this.video.duration.toString())
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:site_name', 'PeerTube')
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:url', window.location.href)
this.metaService.setTag('url', window.location.href)
2016-11-04 16:37:44 +00:00
}
2016-03-14 12:50:19 +00:00
}