Example #1
0
    public async Task <IActionResult> OnGet(string videoId, string?startTime = null)
    {
        var video = await _getVideoService.ExecuteAsync(videoId);

        if (video?.Data == null)
        {
            return(NotFound(videoId));
        }

        var oEmbed = await _getOEmbedVideoService.ExecuteAsync(video.Data.Link);

        if (oEmbed?.Data == null)
        {
            return(NotFound(videoId));
        }

        var spec         = new ArchiveVideoByVideoIdSpec(videoId);
        var archiveVideo = await _repository.GetBySpecAsync(spec);

        if (archiveVideo == null)
        {
            return(NotFound(videoId));
        }

        OEmbedViewModel             = new OEmbedViewModel(oEmbed.Data);
        OEmbedViewModel.Name        = archiveVideo.Title;
        OEmbedViewModel.Password    = video.Data.Password;
        OEmbedViewModel.Description = _markdownService.RenderHTMLFromMD(archiveVideo.Description);
        OEmbedViewModel
        .AddStartTime(startTime)
        .BuildHtml(video.Data.Link);

        return(Page());
    }
    public async Task <IActionResult> PutToggleFavoriteVideo([FromRoute] string vimeoVideoId)
    {
        var currentUserName = User.Identity !.Name;
        var applicationUser = await _userManager.FindByNameAsync(currentUserName);

        var memberSpec = new  MemberByUserIdWithFavoriteArchiveVideosSpec(applicationUser.Id);
        var member     = await _memberRepository.GetBySpecAsync(memberSpec);

        if (member is null)
        {
            return(Unauthorized());
        }

        var videoSpec    = new ArchiveVideoByVideoIdSpec(vimeoVideoId);
        var archiveVideo = await _repository.GetBySpecAsync(videoSpec);

        if (archiveVideo == null)
        {
            return(NotFound($"Video Not Found {vimeoVideoId}"));
        }

        if (member.FavoriteArchiveVideos.Any(v => v.ArchiveVideoId == archiveVideo.Id))
        {
            member.RemoveFavoriteArchiveVideo(archiveVideo);
        }
        else
        {
            member.AddFavoriteArchiveVideo(archiveVideo);
        }

        await _memberRepository.UpdateAsync(member);

        return(Ok(new { archiveVideo.VideoId }));
    }
Example #3
0
    public async Task <IActionResult> OnPostAsync(string id)
    {
        if (id == null)
        {
            return(NotFound());
        }

        var video = await _getVideoService.ExecuteAsync(id);

        if (video?.Data == null)
        {
            return(NotFound());
        }

        await _deleteVideoService.ExecuteAsync(id);

        var spec         = new ArchiveVideoByVideoIdSpec(id);
        var archiveVideo = await _repository.GetBySpecAsync(spec);

        if (archiveVideo != null)
        {
            await _repository.DeleteAsync(archiveVideo);
        }

        return(RedirectToPage("./Index"));
    }
    public async Task <IActionResult> UpdateVideoThumbnailsAsync(long videoId)
    {
        var apiKey = Request.Headers[Constants.ConfigKeys.ApiKey];

        if (apiKey != _expectedApiKey)
        {
            return(Unauthorized());
        }

        var spec       = new ArchiveVideoByVideoIdSpec(videoId.ToString());
        var existVideo = await _repository.GetBySpecAsync(spec);

        if (existVideo == null)
        {
            return(BadRequest());
        }

        var response = await _getVideoService.ExecuteAsync(videoId.ToString());

        if (response?.Data == null)
        {
            return(BadRequest("Video Not Found!"));
        }

        var existThumbsResponse = await _getAllAnimatedThumbnailService.ExecuteAsync(new GetAnimatedThumbnailRequest(videoId, null));

        if (existThumbsResponse.Data.Total <= 0)
        {
            var getAnimatedThumbnailResult = await _createAnimatedThumbnailsService.ExecuteAsync(videoId);

            if (getAnimatedThumbnailResult == null)
            {
                return(BadRequest());
            }
            existVideo.AnimatedThumbnailUri = getAnimatedThumbnailResult.AnimatedThumbnailUri;
        }
        else
        {
            existVideo.AnimatedThumbnailUri = existThumbsResponse.Data.Data.FirstOrDefault()?.AnimatedThumbnailUri;
        }


        await _repository.UpdateAsync(existVideo);

        return(Ok(existVideo));
    }
Example #5
0
    public async Task <IActionResult> OnGet(string videoId, string?startTime = null)
    {
        var video = await _getVideoService.ExecuteAsync(videoId);

        if (video?.Data == null)
        {
            return(NotFound($"Video Not Found {videoId}"));
        }

        var oEmbed = await _getOEmbedVideoService.ExecuteAsync(video.Data.Link);

        if (oEmbed?.Data == null)
        {
            return(NotFound($"Video Not Found {videoId}"));
        }

        var videoSpec    = new ArchiveVideoByVideoIdSpec(videoId);
        var archiveVideo = await _repository.GetBySpecAsync(videoSpec);

        if (archiveVideo == null)
        {
            return(NotFound($"Video Not Found {videoId}"));
        }

        archiveVideo.Views++;
        await _repository.UpdateAsync(archiveVideo);

        var currentUserName = User.Identity !.Name;
        var applicationUser = await _userManager.FindByNameAsync(currentUserName);

        var memberSpec = new MemberByUserIdWithFavoriteArchiveVideosSpec(applicationUser.Id);
        var member     = await _memberRepository.GetBySpecAsync(memberSpec);

        OEmbedViewModel               = new OEmbedViewModel(oEmbed?.Data);
        OEmbedViewModel.VideoId       = int.Parse(archiveVideo.VideoId);
        OEmbedViewModel.Name          = archiveVideo.Title;
        OEmbedViewModel.Password      = video?.Data?.Password;
        OEmbedViewModel.DescriptionMd = _markdownService.RenderHTMLFromMD(archiveVideo.Description);
        OEmbedViewModel.Description   = archiveVideo.Description;
        OEmbedViewModel
        .AddStartTime(startTime)
        .BuildHtml(video?.Data?.Link);
        OEmbedViewModel.IsMemberFavorite = member.FavoriteArchiveVideos.Any(fav => fav.ArchiveVideoId == archiveVideo.Id);

        return(Page());
    }
    public async Task <IActionResult> DeleteVideoThAsync([FromRoute] string vimeoVideoId)
    {
        var apiKey = Request.Headers[Constants.ConfigKeys.ApiKey];

        if (apiKey != _expectedApiKey)
        {
            return(Unauthorized());
        }

        var spec       = new ArchiveVideoByVideoIdSpec(vimeoVideoId);
        var existVideo = await _repository.GetBySpecAsync(spec);

        if (existVideo != null)
        {
            await _repository.DeleteAsync(existVideo);
        }

        await _deleteVideoService.ExecuteAsync(vimeoVideoId);

        return(Ok());
    }