mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
core: clean up image download code (#13862)
This commit is contained in:
@@ -15,39 +15,39 @@ namespace Jackett.Server.Controllers
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[DownloadActionFilter]
|
[DownloadActionFilter]
|
||||||
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
[Route("img/{indexerID}")]
|
[Route("img/{indexerId}")]
|
||||||
public class ImageController : Controller
|
public class ImageController : Controller
|
||||||
{
|
{
|
||||||
private readonly ServerConfig serverConfig;
|
private readonly ServerConfig _serverConfig;
|
||||||
private readonly Logger logger;
|
private readonly Logger _logger;
|
||||||
private readonly IIndexerManagerService indexerService;
|
private readonly IIndexerManagerService _indexerService;
|
||||||
private readonly IProtectionService protectionService;
|
private readonly IProtectionService _protectionService;
|
||||||
|
|
||||||
public ImageController(IIndexerManagerService i, Logger l, IProtectionService ps, ServerConfig sConfig)
|
public ImageController(IIndexerManagerService i, Logger l, IProtectionService ps, ServerConfig sConfig)
|
||||||
{
|
{
|
||||||
serverConfig = sConfig;
|
_serverConfig = sConfig;
|
||||||
logger = l;
|
_logger = l;
|
||||||
indexerService = i;
|
_indexerService = i;
|
||||||
protectionService = ps;
|
_protectionService = ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> DownloadImage(string indexerID, string path, string jackett_apikey, string file)
|
public async Task<IActionResult> DownloadImageAsync(string indexerId, string path, string jackett_apikey, string file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (serverConfig.APIKey != jackett_apikey)
|
if (_serverConfig.APIKey != jackett_apikey)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var indexer = indexerService.GetWebIndexer(indexerID);
|
var indexer = _indexerService.GetWebIndexer(indexerId);
|
||||||
if (!indexer.IsConfigured)
|
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.");
|
return Forbid("This indexer is not configured.");
|
||||||
}
|
}
|
||||||
|
|
||||||
path = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(path));
|
path = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(path));
|
||||||
path = protectionService.UnProtect(path);
|
path = _protectionService.UnProtect(path);
|
||||||
|
|
||||||
var target = new Uri(path, UriKind.RelativeOrAbsolute);
|
var target = new Uri(path, UriKind.RelativeOrAbsolute);
|
||||||
var response = await indexer.DownloadImage(target);
|
var response = await indexer.DownloadImage(target);
|
||||||
@@ -64,7 +64,9 @@ namespace Jackett.Server.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.Debug($"Error downloading image. indexer: {indexerID} path: {path}\n{e}");
|
_logger.Debug($"Error downloading image. " +
|
||||||
|
$"indexer: {indexerId.Replace(Environment.NewLine, "")} " +
|
||||||
|
$"path: {path.Replace(Environment.NewLine, "")}\n{e}");
|
||||||
return new StatusCodeResult((int)System.Net.HttpStatusCode.InternalServerError);
|
return new StatusCodeResult((int)System.Net.HttpStatusCode.InternalServerError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user