private static async Task <bool> ValidateUrl(string url, string callbackUrl) { var urlParser = new UrlTypeParser(); var urlType = await urlParser.GetUrlType(url); return(urlType != UrlType.Invalid); }
private static async Task <bool> ProcessUrl(string url, string callbackUrl) { //get the type of the URL var urlParser = new UrlTypeParser(); var urlType = await urlParser.GetUrlType(url); string outputFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"{System.Guid.NewGuid()}.mp3"); //perform the appropriate processing switch (urlType) { case UrlType.Direct: outputFile = await new DirectDownloader().DownloadFromUrl(url, outputFile); break; default: throw new UnknownUrlTypeException($"URL: {url}\n\tcannot be processed"); } //and here is where it gets tricky // upload it to the appropriate target return(!string.IsNullOrEmpty(outputFile) && System.IO.File.Exists(outputFile)); }
public async Task <ActionResult <PodcastEntryViewModel> > Post([FromBody] PodcastEntryViewModel item) { if (!ModelState.IsValid) { return(BadRequest("Invalid podcast entry posted")); } PodcastEntry entry; if (item.Id != null) { entry = await _repository.GetAsync(item.Id); _mapper.Map(item, entry); } else { entry = _mapper.Map <PodcastEntryViewModel, PodcastEntry>(item); } if (entry is null) { return(BadRequest()); } if (entry.ProcessingStatus == ProcessingStatus.Uploading || entry.ProcessingStatus == ProcessingStatus.Processed) { // we're editing an existing entry await _repository.AddOrUpdateWithTags(entry); await _unitOfWork.CompleteAsync(); var result = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry); return(Ok(result)); } //we're adding a new entry //TODO: This should return the properties bundle //with the status as a member var parser = new UrlTypeParser(); var urlType = await parser.GetUrlType(entry.SourceUrl); if (!urlType.Equals(UrlType.Invalid) && !urlType.Equals(UrlType.Playlist) && !urlType.Equals(UrlType.Channel)) { // check user quota var result = await _preProcessor.PreProcessEntry( _applicationUser, entry); switch (result) { case EntryProcessResult.QuotaExceeded: return(StatusCode(402)); case EntryProcessResult.GeneralFailure: return(BadRequest()); } _repository.GetContext() .Entry(entry) .State = EntityState.Detached; entry = await _repository.GetAsync(entry.Id); return(_mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry)); } if (urlType.Equals(UrlType.Playlist)) { entry.ProcessingStatus = ProcessingStatus.Deferred; var result = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry); return(Accepted(result)); } return(BadRequest("Failed to create podcast entry")); }