mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
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
|
namespace NzbDrone.Api.Frontend
|
||||||
{
|
{
|
||||||
public interface IMapHttpRequestsToDisk
|
public interface IMapHttpRequestsToDisk
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Nancy;
|
using Nancy;
|
||||||
|
using NzbDrone.Core.MediaCover;
|
||||||
using NzbDrone.Core.SeriesStats;
|
using NzbDrone.Core.SeriesStats;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
using NzbDrone.Api.Validation;
|
using NzbDrone.Api.Validation;
|
||||||
@ -14,12 +15,14 @@ public class SeriesModule : NzbDroneRestModule<SeriesResource>
|
|||||||
{
|
{
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly ISeriesService _seriesService;
|
||||||
private readonly ISeriesStatisticsService _seriesStatisticsService;
|
private readonly ISeriesStatisticsService _seriesStatisticsService;
|
||||||
|
private readonly IMapCoversToLocal _coverMapper;
|
||||||
|
|
||||||
public SeriesModule(ISeriesService seriesService, ISeriesStatisticsService seriesStatisticsService)
|
public SeriesModule(ISeriesService seriesService, ISeriesStatisticsService seriesStatisticsService, IMapCoversToLocal coverMapper)
|
||||||
: base("/Series")
|
: base("/Series")
|
||||||
{
|
{
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
_seriesStatisticsService = seriesStatisticsService;
|
_seriesStatisticsService = seriesStatisticsService;
|
||||||
|
_coverMapper = coverMapper;
|
||||||
|
|
||||||
GetResourceAll = AllSeries;
|
GetResourceAll = AllSeries;
|
||||||
GetResourceById = GetSeries;
|
GetResourceById = GetSeries;
|
||||||
@ -51,9 +54,9 @@ private Response GetSeries(string slug)
|
|||||||
private List<SeriesResource> AllSeries()
|
private List<SeriesResource> AllSeries()
|
||||||
{
|
{
|
||||||
var seriesStats = _seriesStatisticsService.SeriesStatistics();
|
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);
|
var stats = seriesStats.SingleOrDefault(ss => ss.SeriesId == s.Id);
|
||||||
if (stats == null) continue;
|
if (stats == null) continue;
|
||||||
@ -64,12 +67,18 @@ private List<SeriesResource> AllSeries()
|
|||||||
s.NextAiring = stats.NextAiring;
|
s.NextAiring = stats.NextAiring;
|
||||||
}
|
}
|
||||||
|
|
||||||
return seriesModels;
|
MapCoversToLocal(seriesResources.ToArray());
|
||||||
|
|
||||||
|
return seriesResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SeriesResource GetSeries(int id)
|
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)
|
private SeriesResource AddSeries(SeriesResource seriesResource)
|
||||||
@ -92,6 +101,14 @@ private void DeleteSeries(int id)
|
|||||||
var deleteFiles = Convert.ToBoolean(Request.Headers["deleteFiles"].FirstOrDefault());
|
var deleteFiles = Convert.ToBoolean(Request.Headers["deleteFiles"].FirstOrDefault());
|
||||||
_seriesService.DeleteSeries(id, deleteFiles);
|
_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 @@ public static bool IsSimpleType(this Type type)
|
|||||||
|| type == typeof(string)
|
|| type == typeof(string)
|
||||||
|| type == typeof(DateTime)
|
|| type == typeof(DateTime)
|
||||||
|| type == typeof(Version)
|
|| type == typeof(Version)
|
||||||
|| type == typeof(Decimal)
|
|| type == typeof(Decimal);
|
||||||
|| type.GetInterface("IEmbeddedDocument") != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsReadable(this PropertyInfo propertyInfo)
|
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.Common;
|
||||||
using NzbDrone.Core.MediaCover;
|
using NzbDrone.Core.MediaCover;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.MediaCoverTests
|
namespace NzbDrone.Core.Test.MediaCoverTests
|
||||||
{
|
{
|
||||||
@ -11,9 +16,44 @@ public class MediaCoverServiceFixture : CoreTest<MediaCoverService>
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
Mocker.SetConstant(new HttpProvider(new EnvironmentProvider()));
|
//Mocker.SetConstant(new HttpProvider(new EnvironmentProvider()));
|
||||||
Mocker.SetConstant(new DiskProvider());
|
//Mocker.SetConstant(new DiskProvider());
|
||||||
Mocker.SetConstant(new EnvironmentProvider());
|
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 NUnit.Framework;
|
||||||
|
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using FluentAssertions;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.Model;
|
|
||||||
using NzbDrone.Core.Notifications;
|
|
||||||
using NzbDrone.Core.Notifications.Growl;
|
using NzbDrone.Core.Notifications.Growl;
|
||||||
using NzbDrone.Core.Providers;
|
|
||||||
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.NotificationTests
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
|
||||||
{
|
{
|
||||||
[Explicit]
|
[Explicit]
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -11,7 +9,7 @@
|
|||||||
using NzbDrone.Core.Notifications.Plex;
|
using NzbDrone.Core.Notifications.Plex;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.NotificationTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
|
||||||
|
@ -1,21 +1,11 @@
|
|||||||
using System;
|
using FluentAssertions;
|
||||||
|
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using FluentAssertions;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Model;
|
|
||||||
using NzbDrone.Core.Notifications.Prowl;
|
using NzbDrone.Core.Notifications.Prowl;
|
||||||
using NzbDrone.Core.Providers;
|
|
||||||
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
|
||||||
using Prowlin;
|
using Prowlin;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.NotificationTests
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
|
||||||
{
|
{
|
||||||
[Explicit]
|
[Explicit]
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
@ -150,12 +150,10 @@
|
|||||||
<Compile Include="MetadataSourceTests\TracktProxyFixture.cs" />
|
<Compile Include="MetadataSourceTests\TracktProxyFixture.cs" />
|
||||||
<Compile Include="NotificationTests\NotificationServiceFixture.cs" />
|
<Compile Include="NotificationTests\NotificationServiceFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\GetJsonVersionFixture.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\ActivePlayersFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\Http\CheckForErrorFixture.cs" />
|
<Compile Include="NotificationTests\Xbmc\Http\CheckForErrorFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\Http\GetSeriesPathFixture.cs" />
|
<Compile Include="NotificationTests\Xbmc\Http\GetSeriesPathFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\Http\UpdateFixture.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\ActivePlayersFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\Json\CheckForErrorFixture.cs" />
|
<Compile Include="NotificationTests\Xbmc\Json\CheckForErrorFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\Json\GetSeriesPathFixture.cs" />
|
<Compile Include="NotificationTests\Xbmc\Json\GetSeriesPathFixture.cs" />
|
||||||
@ -198,7 +196,6 @@
|
|||||||
<Compile Include="HelperTests\SortHelperTest.cs" />
|
<Compile Include="HelperTests\SortHelperTest.cs" />
|
||||||
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
||||||
<Compile Include="Qualities\QualitySizeServiceFixture.cs" />
|
<Compile Include="Qualities\QualitySizeServiceFixture.cs" />
|
||||||
<Compile Include="NotificationTests\Xbmc\XbmcServiceFixture.cs" />
|
|
||||||
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||||
<Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" />
|
<Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" />
|
||||||
<Compile Include="FluentTest.cs" />
|
<Compile Include="FluentTest.cs" />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
@ -10,7 +11,8 @@ namespace NzbDrone.Core.MediaCover
|
|||||||
{
|
{
|
||||||
public class MediaCoverService :
|
public class MediaCoverService :
|
||||||
IHandleAsync<SeriesUpdatedEvent>,
|
IHandleAsync<SeriesUpdatedEvent>,
|
||||||
IHandleAsync<SeriesDeletedEvent>
|
IHandleAsync<SeriesDeletedEvent>,
|
||||||
|
IMapCoversToLocal
|
||||||
{
|
{
|
||||||
private readonly IHttpProvider _httpProvider;
|
private readonly IHttpProvider _httpProvider;
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
@ -80,5 +82,26 @@ private string GetSeriesCoverPath(int seriesId)
|
|||||||
{
|
{
|
||||||
return Path.Combine(_coverRootFolder, seriesId.ToString());
|
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;
|
return percent;
|
||||||
},
|
},
|
||||||
banner : function () {
|
|
||||||
return "/mediacover/" + this.get('id') + "/banner.jpg";
|
|
||||||
},
|
|
||||||
poster : function () {
|
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 () {
|
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 () {
|
traktUrl : function () {
|
||||||
return "http://trakt.tv/show/" + this.get('titleSlug');
|
return "http://trakt.tv/show/" + this.get('titleSlug');
|
||||||
|
Loading…
Reference in New Issue
Block a user