From 3f4433938108eb4cb132cf3885355193714a90ba Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 19 May 2013 18:19:10 -0700 Subject: [PATCH] static resources are mapped to full path instead of relative. --- NzbDrone.Api.Test/NzbDrone.Api.Test.csproj | 1 - .../StaticResourceMapperFixture.cs | 21 ------------------- NzbDrone.Api/Frontend/StaticResourceMapper.cs | 9 +++++++- NzbDrone.Common.Test/PathExtensionFixture.cs | 2 +- NzbDrone.Common/IEnvironmentProvider.cs | 1 + 5 files changed, 10 insertions(+), 24 deletions(-) delete mode 100644 NzbDrone.Api.Test/StaticResourceMapperFixture.cs diff --git a/NzbDrone.Api.Test/NzbDrone.Api.Test.csproj b/NzbDrone.Api.Test/NzbDrone.Api.Test.csproj index 476e0707d..e8c915e4d 100644 --- a/NzbDrone.Api.Test/NzbDrone.Api.Test.csproj +++ b/NzbDrone.Api.Test/NzbDrone.Api.Test.csproj @@ -75,7 +75,6 @@ - diff --git a/NzbDrone.Api.Test/StaticResourceMapperFixture.cs b/NzbDrone.Api.Test/StaticResourceMapperFixture.cs deleted file mode 100644 index 90d2232b8..000000000 --- a/NzbDrone.Api.Test/StaticResourceMapperFixture.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; -using NUnit.Framework; -using NzbDrone.Api.Frontend; -using NzbDrone.Test.Common; - -namespace NzbDrone.Api.Test -{ - [TestFixture] - public class StaticResourceMapperFixture : TestBase - { - [TestCase("/app.js", Result = "ui|app.js")] - [TestCase("/series/app.js", Result = "ui|series|app.js")] - [TestCase("series/app.js", Result = "ui|series|app.js")] - [TestCase("Series/App.js", Result = "ui|series|app.js")] - public string should_map_paths(string path) - { - return Subject.Map(path).Replace(Path.DirectorySeparatorChar, '|'); - } - - } -} diff --git a/NzbDrone.Api/Frontend/StaticResourceMapper.cs b/NzbDrone.Api/Frontend/StaticResourceMapper.cs index 384705e2f..d269d643c 100644 --- a/NzbDrone.Api/Frontend/StaticResourceMapper.cs +++ b/NzbDrone.Api/Frontend/StaticResourceMapper.cs @@ -1,19 +1,26 @@ using System.IO; using System.Linq; +using NzbDrone.Common; namespace NzbDrone.Api.Frontend { public class StaticResourceMapper : IMapHttpRequestsToDisk { + private readonly IEnvironmentProvider _environmentProvider; private static readonly string[] Extensions = new[] { ".css", ".js", ".html", ".htm", ".jpg", ".jpeg", ".icon", ".gif", ".png", ".woff", ".ttf" }; + public StaticResourceMapper(IEnvironmentProvider environmentProvider) + { + _environmentProvider = environmentProvider; + } + public string Map(string resourceUrl) { var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar); path = path.Trim(Path.DirectorySeparatorChar).ToLower(); - return Path.Combine("ui", path); + return Path.Combine(_environmentProvider.StartUpPath, "ui", path); } public bool CanHandle(string resourceUrl) diff --git a/NzbDrone.Common.Test/PathExtensionFixture.cs b/NzbDrone.Common.Test/PathExtensionFixture.cs index 1acb557ce..6c313190e 100644 --- a/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -73,7 +73,7 @@ public void normalize_path_exception_null() [Test] public void AppDataDirectory_path_test() { - GetEnvironmentProvider().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\App_Data\"); + GetEnvironmentProvider().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\"); } diff --git a/NzbDrone.Common/IEnvironmentProvider.cs b/NzbDrone.Common/IEnvironmentProvider.cs index ed9c163f2..308f44ca8 100644 --- a/NzbDrone.Common/IEnvironmentProvider.cs +++ b/NzbDrone.Common/IEnvironmentProvider.cs @@ -12,6 +12,7 @@ public interface IEnvironmentProvider string SystemTemp { get; } Version Version { get; } DateTime BuildDateTime { get; } + string StartUpPath { get; } Version GetOsVersion(); }