2013-09-20 07:31:02 +00:00
|
|
|
using System;
|
2013-08-20 02:31:26 +00:00
|
|
|
using System.IO;
|
2013-09-17 22:03:16 +00:00
|
|
|
using Nancy;
|
2013-09-20 07:31:02 +00:00
|
|
|
using Nancy.Responses;
|
2013-08-20 06:23:36 +00:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common;
|
2013-08-20 02:31:26 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-09-20 07:31:02 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-08-20 02:31:26 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Api.Frontend.Mappers
|
|
|
|
{
|
2013-08-20 06:23:36 +00:00
|
|
|
public class IndexHtmlMapper : StaticResourceMapperBase
|
2013-08-20 02:31:26 +00:00
|
|
|
{
|
2013-08-20 06:23:36 +00:00
|
|
|
private readonly IDiskProvider _diskProvider;
|
2013-09-20 07:31:02 +00:00
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
2013-08-20 02:31:26 +00:00
|
|
|
private readonly string _indexPath;
|
|
|
|
|
2013-09-20 07:31:02 +00:00
|
|
|
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
|
|
|
IDiskProvider diskProvider,
|
|
|
|
IConfigFileProvider configFileProvider,
|
|
|
|
Logger logger)
|
2013-08-20 06:23:36 +00:00
|
|
|
: base(diskProvider, logger)
|
2013-08-20 02:31:26 +00:00
|
|
|
{
|
2013-08-20 06:23:36 +00:00
|
|
|
_diskProvider = diskProvider;
|
2013-09-20 07:31:02 +00:00
|
|
|
_configFileProvider = configFileProvider;
|
2013-08-20 02:31:26 +00:00
|
|
|
_indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html");
|
|
|
|
}
|
|
|
|
|
2013-08-20 06:23:36 +00:00
|
|
|
protected override string Map(string resourceUrl)
|
2013-08-20 02:31:26 +00:00
|
|
|
{
|
|
|
|
return _indexPath;
|
|
|
|
}
|
|
|
|
|
2013-08-20 06:23:36 +00:00
|
|
|
public override bool CanHandle(string resourceUrl)
|
2013-08-20 02:31:26 +00:00
|
|
|
{
|
|
|
|
return !resourceUrl.Contains(".");
|
|
|
|
}
|
2013-08-20 06:23:36 +00:00
|
|
|
|
2013-09-17 22:03:16 +00:00
|
|
|
public override Response GetResponse(string resourceUrl)
|
|
|
|
{
|
|
|
|
var response = base.GetResponse(resourceUrl);
|
|
|
|
response.Headers["X-UA-Compatible"] = "IE=edge";
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2013-08-20 06:23:36 +00:00
|
|
|
protected override Stream GetContentStream(string filePath)
|
|
|
|
{
|
|
|
|
return StringToStream(GetIndexText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetIndexText()
|
|
|
|
{
|
|
|
|
var text = _diskProvider.ReadAllText(_indexPath);
|
|
|
|
|
|
|
|
text = text.Replace(".css", ".css?v=" + BuildInfo.Version);
|
|
|
|
text = text.Replace(".js", ".js?v=" + BuildInfo.Version);
|
2013-09-20 22:19:48 +00:00
|
|
|
text = text.Replace("API_KEY", _configFileProvider.ApiKey);
|
2013-08-20 06:23:36 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2013-08-20 02:31:26 +00:00
|
|
|
}
|
|
|
|
}
|