public async Task <JsonNetResult> GetLatestStatus(GetLatestStatusViewModel model) { EncodingJobProgress status = await _uploads.GetStatusForVideo(model.VideoId); // If there isn't a status (yet) just return queued with a timestamp from 30 seconds ago if (status == null || string.IsNullOrEmpty(status.CurrentState)) { return(JsonSuccess(new LatestStatusViewModel { Status = "Queued", StatusDate = DateTimeOffset.UtcNow.AddSeconds(-30) })); } // If the job is finished, see if the video catalog has a location for the video yet (i.e. knows about it) string currentState = status.CurrentState; if (currentState == "Finished") { VideoDetails videoDetails = await _videoCatalog.GetVideo(model.VideoId); if (videoDetails.Location != null) { currentState = "Ready for Playback"; } } return(JsonSuccess(new LatestStatusViewModel { StatusDate = status.StatusDate, Status = currentState })); }
public async Task <ViewResult> View(Guid videoId) { // Get the views for the video and try to find the video by id (in parallel) Task <PlayStats> videoViewsTask = _stats.GetNumberOfPlays(videoId); Task <VideoDetails> videoDetailsTask = _videoCatalog.GetVideo(videoId); await Task.WhenAll(videoViewsTask, videoDetailsTask); VideoDetails videoDetails = videoDetailsTask.Result; if (videoDetails == null) { throw new ArgumentException(string.Format("Could not find a video with id {0}", videoId)); } // TODO: Better way than client-side JOIN? UserProfileViewModel profile = await GetUserProfile(videoDetails.UserId); bool inProgress = videoDetails.LocationType == VideoLocationType.Upload && videoDetails.Location == null; // Found the video, display it return(View(new ViewVideoViewModel { VideoId = videoId, Title = videoDetails.Name, Description = videoDetails.Description, LocationType = videoDetails.LocationType, Location = videoDetails.Location, Tags = videoDetails.Tags, UploadDate = videoDetails.AddedDate, InProgress = inProgress, Author = profile, Views = videoViewsTask.Result.Views })); }
public async Task <IActionResult> UpdateVideo(Guid id, [FromForm] IFormFile file, [FromForm] string jsonString) { if (!User.IsAdmin()) { _logger.LogInformation("User is not in admin role, admin rights are required for updating the video."); throw new ForbiddenException("User is not in admin role, admin rights are required for updating the video."); } var allowedContentTypes = new List <string> { "image/jpeg" }; var allowedExtensions = new List <string> { "jpg" }; if (file != null) { var splittedFilename = file.FileName.Split("."); if (!allowedContentTypes.Contains(file.ContentType) || !allowedExtensions.Contains(splittedFilename[splittedFilename.Length - 1])) { return(BadRequest()); } } UpdateVideoParam param = JsonConvert.DeserializeObject <UpdateVideoParam>(jsonString); var video = await _catalogService.GetVideo(id); if (video == null) { return(NotFound()); } await _catalogService.UpdateVideo(id, param, file); return(Ok(new { })); }
public async Task <ActionResult <GetVideoResult> > GetVideo(Guid id) { var video = await _catalogService.GetVideo(id); if (video == null) { return(NotFound()); } return(new GetVideoResult { Id = video.Id, Name = video.Name, Description = video.Description, Status = video.Status, ImageFileName = video.ImageFileName, UploadedAt = video.UploadedAt }); }