mirror of https://github.com/Radarr/Radarr
added caching breaker to media cover images.
This commit is contained in:
parent
1585234055
commit
38589742e3
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public interface IMapHttpRequestsToDisk
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.SeriesStats;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Api.Validation;
|
||||
|
@ -14,12 +15,14 @@ namespace NzbDrone.Api.Series
|
|||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly ISeriesStatisticsService _seriesStatisticsService;
|
||||
private readonly IMapCoversToLocal _coverMapper;
|
||||
|
||||
public SeriesModule(ISeriesService seriesService, ISeriesStatisticsService seriesStatisticsService)
|
||||
public SeriesModule(ISeriesService seriesService, ISeriesStatisticsService seriesStatisticsService, IMapCoversToLocal coverMapper)
|
||||
: base("/Series")
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_seriesStatisticsService = seriesStatisticsService;
|
||||
_coverMapper = coverMapper;
|
||||
|
||||
GetResourceAll = AllSeries;
|
||||
GetResourceById = GetSeries;
|
||||
|
@ -51,9 +54,9 @@ namespace NzbDrone.Api.Series
|
|||
private List<SeriesResource> AllSeries()
|
||||
{
|
||||
var seriesStats = _seriesStatisticsService.SeriesStatistics();
|
||||
var seriesModels = ToListResource(_seriesService.GetAllSeries);
|
||||
var seriesResources = ToListResource(_seriesService.GetAllSeries);
|
||||
|
||||
foreach (var s in seriesModels)
|
||||
foreach (var s in seriesResources)
|
||||
{
|
||||
var stats = seriesStats.SingleOrDefault(ss => ss.SeriesId == s.Id);
|
||||
if (stats == null) continue;
|
||||
|
@ -64,12 +67,18 @@ namespace NzbDrone.Api.Series
|
|||
s.NextAiring = stats.NextAiring;
|
||||
}
|
||||
|
||||
return seriesModels;
|
||||
MapCoversToLocal(seriesResources.ToArray());
|
||||
|
||||
return seriesResources;
|
||||
}
|
||||
|
||||
private SeriesResource GetSeries(int id)
|
||||
{
|
||||
return ToResource(_seriesService.GetSeries, id);
|
||||
var resource = ToResource(_seriesService.GetSeries, id);
|
||||
|
||||
MapCoversToLocal(resource);
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
private SeriesResource AddSeries(SeriesResource seriesResource)
|
||||
|
@ -92,6 +101,14 @@ namespace NzbDrone.Api.Series
|
|||
var deleteFiles = Convert.ToBoolean(Request.Headers["deleteFiles"].FirstOrDefault());
|
||||
_seriesService.DeleteSeries(id, deleteFiles);
|
||||
}
|
||||
|
||||
private void MapCoversToLocal(params SeriesResource[] series)
|
||||
{
|
||||
foreach (var seriesResource in series)
|
||||
{
|
||||
_coverMapper.ConvertToLocalUrls(seriesResource.Id, seriesResource.Images);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,7 @@ namespace NzbDrone.Common.Reflection
|
|||
|| type == typeof(string)
|
||||
|| type == typeof(DateTime)
|
||||
|| type == typeof(Version)
|
||||
|| type == typeof(Decimal)
|
||||
|| type.GetInterface("IEmbeddedDocument") != null;
|
||||
|| type == typeof(Decimal);
|
||||
}
|
||||
|
||||
public static bool IsReadable(this PropertyInfo propertyInfo)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaCoverTests
|
||||
{
|
||||
|
@ -11,9 +16,44 @@ namespace NzbDrone.Core.Test.MediaCoverTests
|
|||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.SetConstant(new HttpProvider(new EnvironmentProvider()));
|
||||
Mocker.SetConstant(new DiskProvider());
|
||||
Mocker.SetConstant(new EnvironmentProvider());
|
||||
//Mocker.SetConstant(new HttpProvider(new EnvironmentProvider()));
|
||||
//Mocker.SetConstant(new DiskProvider());
|
||||
Mocker.SetConstant<IEnvironmentProvider>(new EnvironmentProvider());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_convert_trakts_urls_to_local()
|
||||
{
|
||||
var covers = new List<MediaCover.MediaCover>
|
||||
{
|
||||
new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner}
|
||||
};
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetLastFileWrite(It.IsAny<string>()))
|
||||
.Returns(new DateTime(1234));
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
Subject.ConvertToLocalUrls(12, covers);
|
||||
|
||||
|
||||
covers.Single().Url.Should().Be("/mediacover/12/banner.jpg?lastWrite=1234");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_convert_trakts_urls_to_local_without_time_if_file_doesnt_exist()
|
||||
{
|
||||
var covers = new List<MediaCover.MediaCover>
|
||||
{
|
||||
new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner}
|
||||
};
|
||||
|
||||
|
||||
Subject.ConvertToLocalUrls(12, covers);
|
||||
|
||||
|
||||
covers.Single().Url.Should().Be("/mediacover/12/banner.jpg");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,8 @@
|
|||
using System;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Notifications.Growl;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
namespace NzbDrone.Core.Test.NotificationTests
|
||||
{
|
||||
[Explicit]
|
||||
[TestFixture]
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
@ -11,7 +9,7 @@ using NzbDrone.Common;
|
|||
using NzbDrone.Core.Notifications.Plex;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
namespace NzbDrone.Core.Test.NotificationTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
|
|
|
@ -1,21 +1,11 @@
|
|||
using System;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Notifications.Prowl;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
using Prowlin;
|
||||
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
namespace NzbDrone.Core.Test.NotificationTests
|
||||
{
|
||||
[Explicit]
|
||||
[TestFixture]
|
||||
|
|
|
@ -150,12 +150,10 @@
|
|||
<Compile Include="MetadataSourceTests\TracktProxyFixture.cs" />
|
||||
<Compile Include="NotificationTests\NotificationServiceFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\GetJsonVersionFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\HttpApiProviderFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\ActivePlayersFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\CheckForErrorFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\GetSeriesPathFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\UpdateFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\JsonApiProviderFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Json\ActivePlayersFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Json\CheckForErrorFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Json\GetSeriesPathFixture.cs" />
|
||||
|
@ -198,7 +196,6 @@
|
|||
<Compile Include="HelperTests\SortHelperTest.cs" />
|
||||
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
||||
<Compile Include="Qualities\QualitySizeServiceFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\XbmcServiceFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" />
|
||||
<Compile Include="FluentTest.cs" />
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
|
@ -10,7 +11,8 @@ namespace NzbDrone.Core.MediaCover
|
|||
{
|
||||
public class MediaCoverService :
|
||||
IHandleAsync<SeriesUpdatedEvent>,
|
||||
IHandleAsync<SeriesDeletedEvent>
|
||||
IHandleAsync<SeriesDeletedEvent>,
|
||||
IMapCoversToLocal
|
||||
{
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
|
@ -80,5 +82,26 @@ namespace NzbDrone.Core.MediaCover
|
|||
{
|
||||
return Path.Combine(_coverRootFolder, seriesId.ToString());
|
||||
}
|
||||
|
||||
public void ConvertToLocalUrls(int seriesId, IEnumerable<MediaCover> covers)
|
||||
{
|
||||
foreach (var mediaCover in covers)
|
||||
{
|
||||
var filePath = GetCoverPath(seriesId, mediaCover.CoverType);
|
||||
|
||||
mediaCover.Url = @"/mediacover/" + seriesId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg";
|
||||
|
||||
if (_diskProvider.FileExists(filePath))
|
||||
{
|
||||
var lastWrite = _diskProvider.GetLastFileWrite(filePath);
|
||||
mediaCover.Url += "?lastWrite=" + lastWrite.Ticks;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMapCoversToLocal
|
||||
{
|
||||
void ConvertToLocalUrls(int seriesId, IEnumerable<MediaCover> covers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,27 @@ define(['app', 'Quality/QualityProfileCollection'], function (app, qualityProfil
|
|||
|
||||
return percent;
|
||||
},
|
||||
banner : function () {
|
||||
return "/mediacover/" + this.get('id') + "/banner.jpg";
|
||||
},
|
||||
poster : function () {
|
||||
return "/mediacover/" + this.get('id') + "/poster.jpg";
|
||||
var poster = _.find(this.get('images'), function (image) {
|
||||
return image.coverType === 'poster';
|
||||
});
|
||||
|
||||
if (poster) {
|
||||
return poster.url;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
fanArt : function () {
|
||||
return "/mediacover/" + this.get('id') + "/fanart.jpg";
|
||||
var poster = _.find(this.get('images'), function (image) {
|
||||
return image.coverType === 3;
|
||||
});
|
||||
|
||||
if (poster) {
|
||||
return poster.url;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
traktUrl : function () {
|
||||
return "http://trakt.tv/show/" + this.get('titleSlug');
|
||||
|
|
Loading…
Reference in New Issue