PeerTube/client/src/app/videos/video-watch/video-watch.component.ts

335 lines
10 KiB
TypeScript
Raw Normal View History

2016-11-04 16:23:18 +01:00
import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
2017-04-04 21:37:03 +02:00
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
2016-11-08 20:49:43 +01:00
import * as videojs from 'video.js';
2017-03-10 10:33:36 +01:00
import { MetaService } from '@nglibs/meta';
import { NotificationsService } from 'angular2-notifications';
2016-11-04 16:23:18 +01:00
2017-04-04 21:37:03 +02:00
import { AuthService, ConfirmService } from '../../core';
import { VideoMagnetComponent } from './video-magnet.component';
import { VideoShareComponent } from './video-share.component';
2017-01-20 19:22:15 +01:00
import { VideoReportComponent } from './video-report.component';
2017-03-08 21:35:43 +01:00
import { RateType, Video, VideoService } from '../shared';
2016-05-31 22:39:36 +02:00
import { WebTorrentService } from './webtorrent.service';
2016-03-14 13:50:19 +01:00
@Component({
selector: 'my-video-watch',
templateUrl: './video-watch.component.html',
styleUrls: [ './video-watch.component.scss' ]
2016-03-14 13:50:19 +01:00
})
2016-07-08 17:15:14 +02:00
export class VideoWatchComponent implements OnInit, OnDestroy {
2017-01-27 11:30:36 +01:00
private static LOADTIME_TOO_LONG: number = 20000;
@ViewChild('videoMagnetModal') videoMagnetModal: VideoMagnetComponent;
@ViewChild('videoShareModal') videoShareModal: VideoShareComponent;
2017-01-20 19:22:15 +01:00
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent;
2016-11-04 16:23:18 +01:00
downloadSpeed: number;
error: boolean = false;
2016-04-29 14:18:14 +02:00
loading: boolean = false;
2016-05-27 17:49:18 +02:00
numPeers: number;
2017-06-11 12:28:22 +02:00
player: videojs.Player;
2016-11-08 21:17:17 +01:00
playerElement: Element;
2016-05-27 17:49:18 +02:00
uploadSpeed: number;
2017-03-08 21:35:43 +01:00
userRating: RateType = null;
video: Video = null;
videoNotFound = false;
2016-03-14 13:50:19 +01:00
2017-01-27 11:30:36 +01:00
private errorTimer: number;
private paramsSub: Subscription;
private errorsSub: Subscription;
private warningsSub: Subscription;
2017-01-27 11:30:36 +01:00
private torrentInfosInterval: number;
2016-03-14 13:50:19 +01:00
constructor(
2016-05-27 17:49:18 +02:00
private elementRef: ElementRef,
2016-08-12 17:35:00 +02:00
private ngZone: NgZone,
2016-07-08 17:15:14 +02:00
private route: ActivatedRoute,
2017-04-04 21:37:03 +02:00
private router: Router,
2016-05-31 22:39:36 +02:00
private videoService: VideoService,
2017-04-04 21:37:03 +02:00
private confirmService: ConfirmService,
2016-11-04 17:37:44 +01:00
private metaService: MetaService,
2017-01-20 19:22:15 +01:00
private webTorrentService: WebTorrentService,
private authService: AuthService,
private notificationsService: NotificationsService
2016-05-31 22:39:36 +02:00
) {}
2016-03-14 13:50:19 +01:00
ngOnInit() {
this.paramsSub = this.route.params.subscribe(routeParams => {
let id = routeParams['id'];
this.videoService.getVideo(id).subscribe(
2017-04-04 21:37:03 +02:00
video => this.onVideoFetched(video),
error => this.videoNotFound = true
);
});
2016-11-08 20:49:43 +01:00
2016-11-08 21:17:17 +01:00
this.playerElement = this.elementRef.nativeElement.querySelector('#video-container');
2016-11-08 20:49:43 +01:00
const videojsOptions = {
controls: true,
autoplay: false
};
const self = this;
2016-11-08 21:17:17 +01:00
videojs(this.playerElement, videojsOptions, function () {
2016-11-08 20:49:43 +01:00
self.player = this;
});
this.errorsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.error('Error', err.message));
this.warningsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.alert('Warning', err.message));
}
ngOnDestroy() {
2016-11-08 21:17:17 +01:00
// Remove WebTorrent stuff
console.log('Removing video from webtorrent.');
2017-01-27 11:30:36 +01:00
window.clearInterval(this.torrentInfosInterval);
window.clearTimeout(this.errorTimer);
2017-04-04 21:37:03 +02:00
if (this.video !== null && this.webTorrentService.has(this.video.magnetUri)) {
this.webTorrentService.remove(this.video.magnetUri);
}
2016-11-08 21:17:17 +01:00
// Remove player
videojs(this.playerElement).dispose();
// Unsubscribe subscriptions
this.paramsSub.unsubscribe();
this.errorsSub.unsubscribe();
this.warningsSub.unsubscribe();
}
loadVideo() {
// Reset the error
this.error = false;
// We are loading the video
2016-04-29 14:18:14 +02:00
this.loading = true;
2016-03-15 13:16:54 +01:00
console.log('Adding ' + this.video.magnetUri + '.');
2016-05-31 22:39:36 +02:00
// The callback might never return if there are network issues
// So we create a timer to inform the user the load is abnormally long
2017-01-27 11:30:36 +01:00
this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG);
2016-05-31 22:39:36 +02:00
this.webTorrentService.add(this.video.magnetUri, (torrent) => {
// Clear the error timer
2017-01-27 11:30:36 +01:00
window.clearTimeout(this.errorTimer);
// Maybe the error was fired by the timer, so reset it
this.error = false;
// We are not loading the video anymore
2016-04-29 14:18:14 +02:00
this.loading = false;
2016-03-15 13:16:54 +01:00
console.log('Added ' + this.video.magnetUri + '.');
2016-11-08 21:17:17 +01:00
torrent.files[0].renderTo(this.playerElement, { autoplay: true }, (err) => {
2016-03-14 13:50:19 +01:00
if (err) {
this.notificationsService.error('Error', 'Cannot append the file in the video element.');
2016-03-14 13:50:19 +01:00
console.error(err);
}
2016-04-08 20:58:07 +02:00
});
2016-08-12 17:35:00 +02:00
this.runInProgress(torrent);
2016-04-08 20:58:07 +02:00
});
2016-03-14 13:50:19 +01:00
}
2016-03-14 22:16:43 +01:00
2017-03-08 21:35:43 +01:00
setLike() {
if (this.isUserLoggedIn() === false) return;
// Already liked this video
if (this.userRating === 'like') return;
this.videoService.setVideoLike(this.video.id)
.subscribe(
() => {
// Update the video like attribute
this.updateVideoRating(this.userRating, 'like');
this.userRating = 'like';
},
err => this.notificationsService.error('Error', err.text)
);
}
setDislike() {
if (this.isUserLoggedIn() === false) return;
// Already disliked this video
if (this.userRating === 'dislike') return;
this.videoService.setVideoDislike(this.video.id)
.subscribe(
() => {
// Update the video dislike attribute
this.updateVideoRating(this.userRating, 'dislike');
this.userRating = 'dislike';
},
err => this.notificationsService.error('Error', err.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 21:22:10 +02:00
removeVideo(event: Event) {
event.preventDefault();
2017-04-26 21:42:36 +02: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 21:22:10 +02:00
this.confirmService.confirm('Do you really want to delete this video?', 'Delete').subscribe(
res => {
if (res === false) return;
this.videoService.removeVideo(this.video.id)
2017-04-26 21:42:36 +02:00
.subscribe(
status => {
this.notificationsService.success('Success', `Video ${this.video.name} deleted.`);
// Go back to the video-list.
this.router.navigate(['/videos/list']);
},
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 21:22:10 +02:00
}
);
}
blacklistVideo(event: Event) {
2017-04-26 21:42:36 +02:00
event.preventDefault();
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 21:22:10 +02:00
this.confirmService.confirm('Do you really want to blacklist this video ?', 'Blacklist').subscribe(
res => {
2017-04-26 21:42:36 +02:00
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 21:22:10 +02:00
2017-04-26 21:42:36 +02:00
this.videoService.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 21:22:10 +02:00
2017-04-26 21:42:36 +02: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 21:22:10 +02:00
}
2017-04-26 21:42:36 +02: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 21:22:10 +02:00
}
2017-01-20 19:22:15 +01:00
showReportModal(event: Event) {
event.preventDefault();
this.videoReportModal.show();
}
2016-11-08 21:11:57 +01:00
showShareModal() {
this.videoShareModal.show();
2016-11-08 21:11:57 +01:00
}
2017-02-26 19:59:51 +01:00
showMagnetUriModal(event: Event) {
event.preventDefault();
this.videoMagnetModal.show();
2016-11-08 21:11:57 +01:00
}
2017-01-20 19:22:15 +01:00
isUserLoggedIn() {
return this.authService.isLoggedIn();
}
canUserUpdateVideo() {
return this.video.isUpdatableBy(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 21:22:10 +02:00
isVideoRemovable() {
return this.video.isRemovableBy(this.authService.getUser());
}
isVideoBlacklistable() {
return this.video.isBlackistableBy(this.authService.getUser());
}
2017-03-08 21:35:43 +01:00
private checkUserRating() {
// Unlogged users do not have ratings
if (this.isUserLoggedIn() === false) return;
this.videoService.getUserVideoRating(this.video.id)
.subscribe(
ratingObject => {
if (ratingObject) {
this.userRating = ratingObject.rating;
}
},
err => this.notificationsService.error('Error', err.text)
);
}
2017-04-04 21:37:03 +02:00
private onVideoFetched(video: Video) {
this.video = video;
let observable;
if (this.video.isVideoNSFWForUser(this.authService.getUser())) {
observable = this.confirmService.confirm('This video is not safe for work. Are you sure you want to watch it?', 'NSFW');
} else {
observable = Observable.of(true);
}
observable.subscribe(
res => {
if (res === false) {
return this.router.navigate([ '/videos/list' ]);
}
this.setOpenGraphTags();
this.loadVideo();
this.checkUserRating();
}
);
}
2017-03-08 21:35:43 +01:00
private updateVideoRating(oldRating: RateType, newRating: RateType) {
let likesToIncrement = 0;
let dislikesToIncrement = 0;
if (oldRating) {
if (oldRating === 'like') likesToIncrement--;
if (oldRating === 'dislike') dislikesToIncrement--;
}
if (newRating === 'like') likesToIncrement++;
if (newRating === 'dislike') dislikesToIncrement++;
this.video.likes += likesToIncrement;
this.video.dislikes += dislikesToIncrement;
}
private loadTooLong() {
this.error = true;
console.error('The video load seems to be abnormally long.');
}
2016-08-12 17:35:00 +02:00
2016-11-04 17:37:44 +01:00
private setOpenGraphTags() {
2017-03-10 10:33:36 +01:00
this.metaService.setTitle(this.video.name);
2016-11-04 17:37:44 +01:00
this.metaService.setTag('og:type', 'video');
this.metaService.setTag('og:title', this.video.name);
this.metaService.setTag('name', this.video.name);
this.metaService.setTag('og:description', this.video.description);
this.metaService.setTag('description', this.video.description);
this.metaService.setTag('og:image', this.video.thumbnailPath);
2017-06-11 11:29:03 +02:00
this.metaService.setTag('og:duration', this.video.duration.toString());
2016-11-04 17:37:44 +01:00
this.metaService.setTag('og:site_name', 'PeerTube');
this.metaService.setTag('og:url', window.location.href);
this.metaService.setTag('url', window.location.href);
}
2016-08-12 17:35:00 +02:00
private runInProgress(torrent: any) {
// Refresh each second
2017-01-27 11:30:36 +01:00
this.torrentInfosInterval = window.setInterval(() => {
2016-08-12 17:35:00 +02:00
this.ngZone.run(() => {
this.downloadSpeed = torrent.downloadSpeed;
this.numPeers = torrent.numPeers;
this.uploadSpeed = torrent.uploadSpeed;
});
}, 1000);
}
2016-03-14 13:50:19 +01:00
}