mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
This commit is contained in:
34
src/Jackett.Server/ActionFilters/DownloadActionFilter.cs
Normal file
34
src/Jackett.Server/ActionFilters/DownloadActionFilter.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace Jackett.Server.ActionFilters
|
||||||
|
{
|
||||||
|
public class DownloadActionFilter: ActionFilterAttribute
|
||||||
|
{
|
||||||
|
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||||
|
{
|
||||||
|
// in Torznab RSS feed the "link" and "enclosure url" attributes are encoded following the RSS specification
|
||||||
|
// replacing & with &
|
||||||
|
// valid link => http://127.0.0.1:9117/dl/1337x/?jackett_apikey=ygm5k29&path=Q2ZESjhBYnJEQUIxeGd&file=Little+Mons
|
||||||
|
// encoded => http://127.0.0.1:9117/dl/1337x/?jackett_apikey=ygm5k29&path=Q2ZESjhBYnJEQUIxeGd&file=Little+Mons
|
||||||
|
// all RSS readers are able to decode the url and show the user the valid link
|
||||||
|
// some Jackett users are not decoding the url properly and this causes a 404 error in Jackett download
|
||||||
|
// this ActionFilter tries to do the decoding as a fallback, the RSS feed we provide is valid!
|
||||||
|
if (filterContext.ActionArguments.ContainsKey("path") || !filterContext.HttpContext.Request.QueryString.HasValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// recover the original query string and parse it manually
|
||||||
|
var qs = filterContext.HttpContext.Request.QueryString.Value;
|
||||||
|
qs = qs.Replace("&", "&");
|
||||||
|
var parsedQs = QueryHelpers.ParseQuery(qs);
|
||||||
|
if (parsedQs == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// inject the arguments in the controller
|
||||||
|
if (parsedQs.ContainsKey("path") && !filterContext.ActionArguments.ContainsKey("path"))
|
||||||
|
filterContext.ActionArguments.Add("path", parsedQs["path"].ToString());
|
||||||
|
if (parsedQs.ContainsKey("file") && !filterContext.ActionArguments.ContainsKey("file"))
|
||||||
|
filterContext.ActionArguments.Add("file", parsedQs["file"].ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -10,10 +10,12 @@ using NLog;
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Jackett.Server.ActionFilters;
|
||||||
|
|
||||||
namespace Jackett.Server.Controllers
|
namespace Jackett.Server.Controllers
|
||||||
{
|
{
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
[DownloadActionFilter]
|
||||||
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
[Route("dl/{indexerID}")]
|
[Route("dl/{indexerID}")]
|
||||||
public class DownloadController : Controller
|
public class DownloadController : Controller
|
||||||
|
Reference in New Issue
Block a user