mirror of https://github.com/Jackett/Jackett
core: clean up torrent download code (#13865)
This commit is contained in:
parent
aac2e5500e
commit
8442a7980f
|
@ -17,40 +17,40 @@ namespace Jackett.Server.Controllers
|
|||
[AllowAnonymous]
|
||||
[DownloadActionFilter]
|
||||
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[Route("dl/{indexerID}")]
|
||||
[Route("dl/{indexerId}")]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
private readonly ServerConfig serverConfig;
|
||||
private readonly Logger logger;
|
||||
private readonly IIndexerManagerService indexerService;
|
||||
private readonly IProtectionService protectionService;
|
||||
private readonly ServerConfig _serverConfig;
|
||||
private readonly Logger _logger;
|
||||
private readonly IIndexerManagerService _indexerService;
|
||||
private readonly IProtectionService _protectionService;
|
||||
|
||||
public DownloadController(IIndexerManagerService i, Logger l, IProtectionService ps, ServerConfig sConfig)
|
||||
{
|
||||
serverConfig = sConfig;
|
||||
logger = l;
|
||||
indexerService = i;
|
||||
protectionService = ps;
|
||||
_serverConfig = sConfig;
|
||||
_logger = l;
|
||||
_indexerService = i;
|
||||
_protectionService = ps;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Download(string indexerID, string path, string jackett_apikey, string file)
|
||||
public async Task<IActionResult> DownloadAsync(string indexerId, string path, string jackett_apikey, string file)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (serverConfig.APIKey != jackett_apikey)
|
||||
if (_serverConfig.APIKey != jackett_apikey)
|
||||
return Unauthorized();
|
||||
|
||||
var indexer = indexerService.GetWebIndexer(indexerID);
|
||||
var indexer = _indexerService.GetWebIndexer(indexerId);
|
||||
|
||||
if (!indexer.IsConfigured)
|
||||
{
|
||||
logger.Warn($"Rejected a request to {indexer.DisplayName} which is unconfigured.");
|
||||
_logger.Warn($"Rejected a request to {indexer.DisplayName} which is unconfigured.");
|
||||
return Forbid("This indexer is not configured.");
|
||||
}
|
||||
|
||||
path = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(path));
|
||||
path = protectionService.UnProtect(path);
|
||||
path = _protectionService.UnProtect(path);
|
||||
|
||||
var target = new Uri(path, UriKind.RelativeOrAbsolute);
|
||||
var downloadBytes = await indexer.Download(target);
|
||||
|
@ -71,7 +71,7 @@ namespace Jackett.Server.Controllers
|
|||
}
|
||||
|
||||
// This will fix torrents where the keys are not sorted, and thereby not supported by Sonarr.
|
||||
byte[] sortedDownloadBytes = null;
|
||||
byte[] sortedDownloadBytes;
|
||||
try
|
||||
{
|
||||
var parser = new BencodeParser();
|
||||
|
@ -81,7 +81,7 @@ namespace Jackett.Server.Controllers
|
|||
catch (Exception e)
|
||||
{
|
||||
var content = indexer.Encoding.GetString(downloadBytes);
|
||||
logger.Error(content);
|
||||
_logger.Error(content);
|
||||
throw new Exception("BencodeParser failed", e);
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,9 @@ namespace Jackett.Server.Controllers
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error($"Error downloading. indexer: {indexerID} path: {path}\n{e}");
|
||||
_logger.Error($"Error downloading. " +
|
||||
$"indexer: {indexerId.Replace(Environment.NewLine, "")} " +
|
||||
$"path: {path.Replace(Environment.NewLine, "")}\n{e}");
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue