コード例 #1
0
        public async Task <IActionResult> GetBySlug(string slug)
        {
            var podcast = await _repository.GetForUserAndSlugAsync(Guid.Parse(_applicationUser.Id), slug);

            if (podcast is null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <Podcast, PodcastViewModel>(podcast)));
        }
コード例 #2
0
        public async Task <ActionResult <PodcastViewModel> > Get(string user, string podcast)
        {
            var result = await _podcastRepository.GetForUserAndSlugAsync(user, podcast);

            if (result is null)
            {
                return(NotFound());
            }

            return(_mapper.Map <Podcast, PodcastViewModel>(result));
        }
コード例 #3
0
        private async Task <Podcast?> __getTargetPodcast(string twitterText, string userId,
                                                         IPodcastRepository podcastRepository)
        {
            _logger.LogDebug($"Finding podcast for tweet");
            var podcastSlug = twitterText
                              .FindStringFollowing(_twitterSettings.Track)
                              .TrimEnd('/');

            if (string.IsNullOrEmpty(podcastSlug))
            {
                return(null);
            }

            if (podcastSlug.Contains("/"))
            {
                podcastSlug = podcastSlug.Split('/').Last();
            }

            var podcast = await podcastRepository.GetForUserAndSlugAsync(Guid.Parse(userId), podcastSlug);

            return(podcast);
        }
コード例 #4
0
        public async Task <IActionResult> Get(string userSlug, string podcastSlug)
        {
            var user = await _userManager.FindBySlugAsync(userSlug);

            if (user is null)
            {
                //check if we have a redirect in place
                var redirect = await _redirectsRepository
                               .GetAll()
                               .Where(r => r.OldSlug == userSlug)
                               .FirstOrDefaultAsync();

                if (redirect is null)
                {
                    return(NotFound());
                }

                user = await _userManager.FindByIdAsync(redirect.ApplicationUserId.ToString());

                if (user is null)
                {
                    return(NotFound());
                }

                var url = Flurl.Url.Combine(_appSettings.RssUrl, user.Slug, podcastSlug);
                return(Redirect(url));
            }

            var podcast = await _podcastRepository.GetForUserAndSlugAsync(userSlug, podcastSlug);

            if (podcast is null)
            {
                return(NotFound());
            }
            try {
                var xml = await ResourceReader.ReadResource("podcast.xml");

                var template = Handlebars.Compile(xml);
                var compiled = new PodcastEnclosureViewModel {
                    Title       = podcast.Title,
                    Description = podcast.Description.RemoveUnwantedHtmlTags(),
                    Author      = "PodNoms Podcasts",
                    Image       = podcast.GetRawImageUrl(_storageOptions.CdnUrl, _imageStorageOptions.ContainerName),
                    Link        = $"{_appSettings.PagesUrl}/{user.Slug}/{podcast.Slug}",
                    PublishDate = podcast.CreateDate.ToRFC822String(),
                    Category    = podcast.Category?.Description,
                    Language    = "en-IE",
                    Copyright   = $"© {DateTime.Now.Year} PodNoms RSS",
                    Owner       = $"{user.FirstName} {user.LastName}",
                    OwnerEmail  = user.Email,
                    ShowUrl     = Flurl.Url.Combine(_appSettings.RssUrl, user.Slug, podcast.Slug),
                    Items       = (
                        from e in podcast.PodcastEntries
                        select new PodcastEnclosureItemViewModel {
                        Title = e.Title.StripNonXmlChars().RemoveUnwantedHtmlTags(),
                        Uid = e.Id.ToString(),
                        Summary = e.Description.StripNonXmlChars().RemoveUnwantedHtmlTags(),
                        Description = e.Description.StripNonXmlChars(),
                        Author = e.Author.StripNonXmlChars().Truncate(252, true),
                        EntryImage = e.GetImageUrl(_storageOptions.CdnUrl, _imageStorageOptions.ContainerName),
                        UpdateDate = e.CreateDate.ToRFC822String(),
                        AudioUrl = e.GetRssAudioUrl(_appSettings.AudioUrl),
                        AudioDuration = TimeSpan.FromSeconds(e.AudioLength).ToString(@"hh\:mm\:ss"),
                        AudioFileSize = e.AudioFileSize
                    }
                        ).ToList()
                };
                var result = template(compiled);
                return(Content(result, "application/xml", Encoding.UTF8));
            } catch (NullReferenceException ex) {
                _logger.LogError(ex, "Error getting RSS", user, userSlug);
            }

            return(NotFound());
        }
コード例 #5
0
        public async Task <IActionResult> Upload(string slug, IFormFile file)
        {
            _logger.LogDebug($"Uploading file for: {slug}");
            if (file is null || file.Length == 0)
            {
                return(BadRequest("No file found in stream"));
            }
            if (file.Length > _audioFileStorageSettings.MaxUploadFileSize)
            {
                return(BadRequest("Maximum file size exceeded"));
            }
            if (!_audioFileStorageSettings.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid file type"));
            }

            var podcast = await _podcastRepository.GetForUserAndSlugAsync(_applicationUser.Slug, slug);

            if (podcast is null)
            {
                _logger.LogError($"Unable to find podcast");
                return(NotFound());
            }

            var entry = new PodcastEntry {
                Title            = Path.GetFileName(Path.GetFileNameWithoutExtension(file.FileName)),
                ImageUrl         = $"{_storageSettings.CdnUrl}/static/images/default-entry.png",
                Processed        = false,
                ProcessingStatus = ProcessingStatus.Processing,
                Podcast          = podcast
            };

            var localFile = await CachedFormFileStorage.CacheItem(_hostingEnvironment.WebRootPath, file);

            _logger.LogDebug($"Local file is: {localFile}");

            _entryRepository.AddOrUpdate(entry);

            _logger.LogDebug("Completing uow");
            await _unitOfWork.CompleteAsync();

            var authToken = _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"].ToString();

            if (string.IsNullOrEmpty(authToken))
            {
                return(Unauthorized("Auth token is empty"));
            }

            //convert uploaded file to extension
            var audioUrl = localFile
                           .Replace(_hostingEnvironment.WebRootPath, string.Empty)
                           .Replace(@"\", "/");

            _logger.LogDebug($"Starting processing jobs for url: {audioUrl}");

            BackgroundJob.Enqueue <ProcessNewEntryJob>(e =>
                                                       e.ProcessEntryFromUploadFile(entry.Id, audioUrl, authToken, null));

            var ret = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry);

            return(Ok(ret));
        }