mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-23 16:23:13 +00:00
Fixed: Fix caching spec for Initialize.js
This commit is contained in:
parent
026a2cace5
commit
6cee554760
2 changed files with 37 additions and 12 deletions
|
@ -30,6 +30,7 @@ public bool IsCacheable(NancyContext context)
|
|||
|
||||
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
|
||||
if (context.Request.Path.EndsWith("index.js")) return false;
|
||||
if (context.Request.Path.EndsWith("initialize.js")) return false;
|
||||
if (context.Request.Path.StartsWith("/feed", StringComparison.CurrentCultureIgnoreCase)) return false;
|
||||
|
||||
if (context.Request.Path.StartsWith("/log", StringComparison.CurrentCultureIgnoreCase) &&
|
||||
|
@ -46,4 +47,4 @@ public bool IsCacheable(NancyContext context)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
@ -12,6 +13,10 @@ public class InitializeJsModule : NancyModule
|
|||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IAnalyticsService _analyticsService;
|
||||
|
||||
private static string _apiKey;
|
||||
private static string _urlBase;
|
||||
private string _generatedContent;
|
||||
|
||||
|
||||
public InitializeJsModule(IConfigFileProvider configFileProvider,
|
||||
IAnalyticsService analyticsService)
|
||||
|
@ -19,6 +24,9 @@ public InitializeJsModule(IConfigFileProvider configFileProvider,
|
|||
_configFileProvider = configFileProvider;
|
||||
_analyticsService = analyticsService;
|
||||
|
||||
_apiKey = configFileProvider.ApiKey;
|
||||
_urlBase = configFileProvider.UrlBase;
|
||||
|
||||
Get["/initialize.js"] = x => Index();
|
||||
}
|
||||
|
||||
|
@ -30,25 +38,41 @@ private Response Index()
|
|||
|
||||
private Stream GetContentStream()
|
||||
{
|
||||
var urlBase = _configFileProvider.UrlBase;
|
||||
var text = GetContent();
|
||||
|
||||
var stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("window.Lidarr = {");
|
||||
writer.WriteLine($" apiRoot: '{urlBase}/api/v1',");
|
||||
writer.WriteLine($" apiKey: '{_configFileProvider.ApiKey}',");
|
||||
writer.WriteLine($" release: '{BuildInfo.Release}',");
|
||||
writer.WriteLine($" version: '{BuildInfo.Version.ToString()}',");
|
||||
writer.WriteLine($" branch: '{_configFileProvider.Branch.ToLower()}',");
|
||||
writer.WriteLine($" analytics: {_analyticsService.IsEnabled.ToString().ToLowerInvariant()},");
|
||||
writer.WriteLine($" urlBase: '{urlBase}',");
|
||||
writer.WriteLine($" isProduction: {RuntimeInfo.IsProduction.ToString().ToLowerInvariant()}");
|
||||
writer.WriteLine("};");
|
||||
|
||||
writer.Write(text);
|
||||
writer.Flush();
|
||||
stream.Position = 0;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
private string GetContent()
|
||||
{
|
||||
if (RuntimeInfo.IsProduction && _generatedContent != null)
|
||||
{
|
||||
return _generatedContent;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine("window.Lidarr = {");
|
||||
builder.AppendLine($" apiRoot: '{_urlBase}/api/v1',");
|
||||
builder.AppendLine($" apiKey: '{_apiKey}',");
|
||||
builder.AppendLine($" release: '{BuildInfo.Release}',");
|
||||
builder.AppendLine($" version: '{BuildInfo.Version.ToString()}',");
|
||||
builder.AppendLine($" branch: '{_configFileProvider.Branch.ToLower()}',");
|
||||
builder.AppendLine($" analytics: {_analyticsService.IsEnabled.ToString().ToLowerInvariant()},");
|
||||
builder.AppendLine($" urlBase: '{_urlBase}',");
|
||||
builder.AppendLine($" isProduction: {RuntimeInfo.IsProduction.ToString().ToLowerInvariant()}");
|
||||
builder.AppendLine("};");
|
||||
|
||||
_generatedContent = builder.ToString();
|
||||
|
||||
return _generatedContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue