public async Task <IActionResult> GetMagnetAsync( [Required][FromQuery] string baseUrl, [Required][FromQuery] string torrentPath, [Required][FromQuery] TorrentSource source) { if (source == TorrentSource.ThePirateBay) { return(BadRequest(new ResponseMessage($"Magnets are not provided for {source}."))); } var dataSource = _helper.Sources()[source]; if (!dataSource.GetSources().Contains(baseUrl)) { return(BadRequest(new ResponseMessage("Base url is not part of known values for this source", baseUrl))); } dataSource.UpdateUsedSource(baseUrl); try { var response = await dataSource.GetTorrentMagnetAsync(torrentPath); return(Ok(new MagnetResponse(response))); } catch (Exception ex) { var fullUrl = Path.Combine(baseUrl, torrentPath); _logger.Information(ex, $"Error retrieving magnet for {source} {fullUrl}"); return(NotFound(new ResponseMessage("Magnet not found", fullUrl))); } }
private async void CheckHealth(object obj) { try { Log.Information("Performing site health check"); var stateDictionary = new Dictionary <TorrentSource, IEnumerable <SourceState> >(); foreach (var source in _helper.Sources()) { var states = new List <SourceState>(); await foreach (var state in source.Value.GetSourceStates()) { states.Add(state); } stateDictionary.Add(source.Key, states); } _cache.WriteSourceStates(stateDictionary); } catch (Exception ex) { Log.Warning(ex, "Site health check failed"); } }