Newznab images handled in controller

Fixed: Missing Newznab Logos won't throw errors
#ND-127 fixed
pull/4/head
Mark McDowall 12 years ago
parent faadb8b6c0
commit 165600301c

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Common;
namespace NzbDrone.Web.Controllers
{
public class ImageController : Controller
{
private readonly DiskProvider _diskProvider;
public ImageController(DiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
public ActionResult Newznab(string name)
{
var dir = Server.MapPath("/Content/Images/Indexers");
var path = Path.Combine(dir, String.Format("{0}.png", name));
if (_diskProvider.FileExists(path))
return File(path, "image/png");
return File(Path.Combine(dir, "Newznab.png"), "image/png");
}
}
}

@ -197,6 +197,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="App_Start\DataTablesMvc.cs" /> <Compile Include="App_Start\DataTablesMvc.cs" />
<Compile Include="App_Start\MiniProfiler.cs" /> <Compile Include="App_Start\MiniProfiler.cs" />
<Compile Include="Controllers\ImageController.cs" />
<Compile Include="Controllers\SearchHistoryController.cs" /> <Compile Include="Controllers\SearchHistoryController.cs" />
<Compile Include="Helpers\Binders\QualityTypesBinder.cs" /> <Compile Include="Helpers\Binders\QualityTypesBinder.cs" />
<Compile Include="Helpers\RenderActionHelper.cs" /> <Compile Include="Helpers\RenderActionHelper.cs" />

@ -63,7 +63,7 @@
// 'display' and 'filter' use the image // 'display' and 'filter' use the image
if (type === 'display' || type === 'filter') { if (type === 'display' || type === 'filter') {
if (source['Indexer'].indexOf("Newznab") === 0) if (source['Indexer'].indexOf("Newznab") === 0)
return "<img src='/Content/Images/Indexers/" + source['Indexer'] + ".png' alt='" + source["Indexer"].replace('_', ' - ') + "' title='" + source["Indexer"].replace('_', ' - ') + "' onerror='this.src=\"/Content/Images/Indexers/Newznab.png\"'>"; return '<img src="/Image/Newznab?name=' + source['Indexer'] + '" alt="' + source['Indexer'].replace('_', ' - ') + '" title="' + source['Indexer'].replace('_', ' - ') + '">';
return "<img src='/Content/Images/Indexers/" + source['Indexer'] + ".png' alt='" + source["Indexer"] + "' title='" + source["Indexer"] + "'>"; return "<img src='/Content/Images/Indexers/" + source['Indexer'] + ".png' alt='" + source["Indexer"] + "' title='" + source["Indexer"] + "'>";
} }

@ -15,7 +15,7 @@
@(Html.GridScriptFor(m => m.SearchHistoryItems, "#searchDetailsGrid") @(Html.GridScriptFor(m => m.SearchHistoryItems, "#searchDetailsGrid")
.PageLength(20) .PageLength(20)
.ChangePageLength(false) .ChangePageLength(false)
.AddColumn(new Column().Image("/Content/Images/Indexers/{Indexer}.png", new { alt = "{Indexer}", title = "{Indexer}" }, "{Indexer}").Sortable(false).Title("").Width("20px")) .AddColumn(new Column().Image("/Image/Newznab?name={Indexer}", new { alt = "{Indexer}", title = "{Indexer}" }, "{Indexer}").Sortable(false).Title("").Width("20px"))
.AddColumn(new Column().DataProperty("ReportTitle").Title("Report Title")) .AddColumn(new Column().DataProperty("ReportTitle").Title("Report Title"))
.AddColumn(new Column().DataProperty("Success").Title("Successful").Width("100px")) .AddColumn(new Column().DataProperty("Success").Title("Successful").Width("100px"))
//.AddColumn(new Column().Image("/Content/Images/{Success}.png", new { alt = "{Success}", title = "{Success}", @class = "gridImage" }, "{Success}").Title("Successful").Width("100px")) //.AddColumn(new Column().Image("/Content/Images/{Success}.png", new { alt = "{Success}", title = "{Success}", @class = "gridImage" }, "{Success}").Title("Successful").Width("100px"))

Loading…
Cancel
Save