lidarr/src/Lidarr.Http/Middleware/CacheableSpecification.cs
ta264 5b2affcabb Fixed: UI not updating on upgrade
(cherry picked from commit d566c1efd42f9a94c524db311e8fa99bc6e0323f)
(cherry picked from commit 4b0586bd3d1cca4682dee53cc5af5ef1fa66978e)
2021-09-26 19:56:50 -04:00

66 lines
1.8 KiB
C#

using System;
using Microsoft.AspNetCore.Http;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
namespace Lidarr.Http.Middleware
{
public interface ICacheableSpecification
{
bool IsCacheable(HttpRequest request);
}
public class CacheableSpecification : ICacheableSpecification
{
public bool IsCacheable(HttpRequest request)
{
if (!RuntimeInfo.IsProduction)
{
return false;
}
if (request.Query.ContainsKey("h"))
{
return true;
}
if (request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
{
if (request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
{
return true;
}
return false;
}
if (request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if (request.Path.Value?.EndsWith("/index.js") ?? false)
{
return false;
}
if (request.Path.Value?.EndsWith("/initialize.js") ?? false)
{
return false;
}
if (request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if (request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
(request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false))
{
return false;
}
return true;
}
}
}