mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-18 21:35:27 -04:00
Compare commits
7 Commits
v4.0.16.29
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31c7647eac | ||
|
|
97e85a908d | ||
|
|
6d91c3b62e | ||
|
|
f30207c3d1 | ||
|
|
028d2414e7 | ||
|
|
cbd7df2c91 | ||
|
|
52972e7efc |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -22,7 +22,7 @@ env:
|
|||||||
FRAMEWORK: net6.0
|
FRAMEWORK: net6.0
|
||||||
RAW_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
RAW_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
||||||
SONARR_MAJOR_VERSION: 4
|
SONARR_MAJOR_VERSION: 4
|
||||||
VERSION: 4.0.16
|
VERSION: 4.0.17
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
backend:
|
backend:
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Plex
|
|||||||
|
|
||||||
if (episodeFile.SeasonNumber == 0)
|
if (episodeFile.SeasonNumber == 0)
|
||||||
{
|
{
|
||||||
episodeFormat = $"SP{episodesInFile.First():00}";
|
episodeFormat = $"SP{episodesInFile.First().EpisodeNumber:00}";
|
||||||
}
|
}
|
||||||
|
|
||||||
content.AppendLine($"Episode: {episodeFormat}: {episodeFile.RelativePath}");
|
content.AppendLine($"Episode: {episodeFormat}: {episodeFile.RelativePath}");
|
||||||
|
|||||||
@@ -286,20 +286,20 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
|
|||||||
|
|
||||||
var watched = GetExistingWatchedStatus(series, episodeFile.RelativePath);
|
var watched = GetExistingWatchedStatus(series, episodeFile.RelativePath);
|
||||||
|
|
||||||
var xmlResult = string.Empty;
|
|
||||||
var xws = new XmlWriterSettings
|
var xws = new XmlWriterSettings
|
||||||
{
|
{
|
||||||
Encoding = Encoding.UTF8,
|
Encoding = Encoding.UTF8,
|
||||||
Indent = true
|
Indent = true,
|
||||||
|
ConformanceLevel = ConformanceLevel.Fragment
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using var sw = new Utf8StringWriter();
|
||||||
|
using var xw = XmlWriter.Create(sw, xws);
|
||||||
|
|
||||||
|
xw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"");
|
||||||
|
|
||||||
foreach (var episode in episodeFile.Episodes.Value)
|
foreach (var episode in episodeFile.Episodes.Value)
|
||||||
{
|
{
|
||||||
var doc = new XDocument
|
|
||||||
{
|
|
||||||
Declaration = new XDeclaration("1.0", "UTF-8", "yes")
|
|
||||||
};
|
|
||||||
|
|
||||||
var image = episode.Images.SingleOrDefault(i => i.CoverType == MediaCoverTypes.Screenshot);
|
var image = episode.Images.SingleOrDefault(i => i.CoverType == MediaCoverTypes.Screenshot);
|
||||||
|
|
||||||
var details = new XElement("episodedetails");
|
var details = new XElement("episodedetails");
|
||||||
@@ -391,17 +391,12 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
|
|||||||
// details.Add(new XElement("credits", tvdbEpisode.Writer.FirstOrDefault()));
|
// details.Add(new XElement("credits", tvdbEpisode.Writer.FirstOrDefault()));
|
||||||
// details.Add(new XElement("director", tvdbEpisode.Directors.FirstOrDefault()));
|
// details.Add(new XElement("director", tvdbEpisode.Directors.FirstOrDefault()));
|
||||||
|
|
||||||
using var sw = new Utf8StringWriter();
|
details.WriteTo(xw);
|
||||||
using var xw = XmlWriter.Create(sw, xws);
|
|
||||||
|
|
||||||
doc.Add(details);
|
|
||||||
doc.Save(xw);
|
|
||||||
xw.Flush();
|
|
||||||
|
|
||||||
xmlResult += sw.ToString();
|
|
||||||
xmlResult += Environment.NewLine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xw.Flush();
|
||||||
|
var xmlResult = sw.ToString();
|
||||||
|
|
||||||
return new MetadataFileResult(GetEpisodeMetadataFilename(episodeFile.RelativePath), xmlResult.Trim(Environment.NewLine.ToCharArray()));
|
return new MetadataFileResult(GetEpisodeMetadataFilename(episodeFile.RelativePath), xmlResult.Trim(Environment.NewLine.ToCharArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<PackageReference Include="Servarr.FluentMigrator.Runner.SQLite" Version="3.3.2.9" />
|
<PackageReference Include="Servarr.FluentMigrator.Runner.SQLite" Version="3.3.2.9" />
|
||||||
<PackageReference Include="Servarr.FluentMigrator.Runner.Postgres" Version="3.3.2.9" />
|
<PackageReference Include="Servarr.FluentMigrator.Runner.Postgres" Version="3.3.2.9" />
|
||||||
<PackageReference Include="FluentValidation" Version="9.5.4" />
|
<PackageReference Include="FluentValidation" Version="9.5.4" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="NLog" Version="5.3.4" />
|
<PackageReference Include="NLog" Version="5.3.4" />
|
||||||
<PackageReference Include="MonoTorrent" Version="2.0.7" />
|
<PackageReference Include="MonoTorrent" Version="2.0.7" />
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ namespace NzbDrone.Host
|
|||||||
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("10.0.0.0"), 8));
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("10.0.0.0"), 8));
|
||||||
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("172.16.0.0"), 12));
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("172.16.0.0"), 12));
|
||||||
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("192.168.0.0"), 16));
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("192.168.0.0"), 16));
|
||||||
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("fc00::"), 7));
|
||||||
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("fe80::"), 10));
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddRouting(options => options.LowercaseUrls = true);
|
services.AddRouting(options => options.LowercaseUrls = true);
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_backupService = backupService;
|
_backupService = backupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => _backupService.GetBackupFolder().TrimEnd(Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var path = resourceUrl.Replace("/backup/", "").Replace('/', Path.DirectorySeparatorChar);
|
var path = resourceUrl.Replace("/backup/", "").Replace('/', Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
return Path.Combine(_backupService.GetBackupFolder(), path);
|
return Path.Combine(FolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanHandle(string resourceUrl)
|
public override bool CanHandle(string resourceUrl)
|
||||||
|
|||||||
@@ -8,13 +8,20 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
{
|
{
|
||||||
public class BrowserConfig : UrlBaseReplacementResourceMapperBase
|
public class BrowserConfig : UrlBaseReplacementResourceMapperBase
|
||||||
{
|
{
|
||||||
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public BrowserConfig(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger)
|
public BrowserConfig(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger)
|
||||||
: base(diskProvider, configFileProvider, logger)
|
: base(diskProvider, configFileProvider, logger)
|
||||||
{
|
{
|
||||||
FilePath = Path.Combine(appFolderInfo.StartUpFolder, configFileProvider.UiFolder, "Content", "browserconfig.xml");
|
_appFolderInfo = appFolderInfo;
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
protected override string FilePath => Path.Combine(FolderPath, "Content", "browserconfig.xml");
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
return FilePath;
|
return FilePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
|
|
||||||
var mapper = _diskMappers.Single(m => m.CanHandle(resourceUrl));
|
var mapper = _diskMappers.Single(m => m.CanHandle(resourceUrl));
|
||||||
var pathToFile = mapper.Map(resourceUrl);
|
var pathToFile = mapper.Map(resourceUrl);
|
||||||
|
|
||||||
|
if (pathToFile == null)
|
||||||
|
{
|
||||||
|
return resourceUrl;
|
||||||
|
}
|
||||||
|
|
||||||
var hash = _hashProvider.ComputeMd5(pathToFile).ToBase64();
|
var hash = _hashProvider.ComputeMd5(pathToFile).ToBase64();
|
||||||
|
|
||||||
return resourceUrl + "?h=" + hash.Trim('=');
|
return resourceUrl + "?h=" + hash.Trim('=');
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var fileName = "favicon.ico";
|
var fileName = "favicon.ico";
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
|
|
||||||
var path = Path.Combine("Content", "Images", "Icons", fileName);
|
var path = Path.Combine("Content", "Images", "Icons", fileName);
|
||||||
|
|
||||||
return Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder, path);
|
return Path.Combine(FolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanHandle(string resourceUrl)
|
public override bool CanHandle(string resourceUrl)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Text.RegularExpressions;
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
namespace Sonarr.Http.Frontend.Mappers
|
namespace Sonarr.Http.Frontend.Mappers
|
||||||
{
|
{
|
||||||
@@ -13,19 +14,22 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
private readonly Lazy<ICacheBreakerProvider> _cacheBreakProviderFactory;
|
private readonly Lazy<ICacheBreakerProvider> _cacheBreakProviderFactory;
|
||||||
private static readonly Regex ReplaceRegex = new Regex(@"(?:(?<attribute>href|src)=\"")(?<path>.*?(?<extension>css|js|png|ico|ics|svg|json))(?:\"")(?:\s(?<nohash>data-no-hash))?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
private static readonly Regex ReplaceRegex = new Regex(@"(?:(?<attribute>href|src)=\"")(?<path>.*?(?<extension>css|js|png|ico|ics|svg|json))(?:\"")(?:\s(?<nohash>data-no-hash))?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
|
private string _urlBase;
|
||||||
private string _generatedContent;
|
private string _generatedContent;
|
||||||
|
|
||||||
protected HtmlMapperBase(IDiskProvider diskProvider,
|
protected HtmlMapperBase(IDiskProvider diskProvider,
|
||||||
|
IConfigFileProvider configFileProvider,
|
||||||
Lazy<ICacheBreakerProvider> cacheBreakProviderFactory,
|
Lazy<ICacheBreakerProvider> cacheBreakProviderFactory,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
: base(diskProvider, logger)
|
: base(diskProvider, logger)
|
||||||
{
|
{
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_cacheBreakProviderFactory = cacheBreakProviderFactory;
|
_cacheBreakProviderFactory = cacheBreakProviderFactory;
|
||||||
|
|
||||||
|
_urlBase = configFileProvider.UrlBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string HtmlPath;
|
protected abstract string HtmlPath { get; }
|
||||||
protected string UrlBase;
|
|
||||||
|
|
||||||
protected override Stream GetContentStream(string filePath)
|
protected override Stream GetContentStream(string filePath)
|
||||||
{
|
{
|
||||||
@@ -62,10 +66,10 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
url = cacheBreakProvider.AddCacheBreakerToPath(match.Groups["path"].Value);
|
url = cacheBreakProvider.AddCacheBreakerToPath(match.Groups["path"].Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $"{match.Groups["attribute"].Value}=\"{UrlBase}{url}\"";
|
return $"{match.Groups["attribute"].Value}=\"{_urlBase}{url}\"";
|
||||||
});
|
});
|
||||||
|
|
||||||
text = text.Replace("__URL_BASE__", UrlBase);
|
text = text.Replace("__URL_BASE__", _urlBase);
|
||||||
|
|
||||||
_generatedContent = text;
|
_generatedContent = text;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
{
|
{
|
||||||
public class IndexHtmlMapper : HtmlMapperBase
|
public class IndexHtmlMapper : HtmlMapperBase
|
||||||
{
|
{
|
||||||
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
||||||
@@ -16,15 +17,16 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
IConfigFileProvider configFileProvider,
|
IConfigFileProvider configFileProvider,
|
||||||
Lazy<ICacheBreakerProvider> cacheBreakProviderFactory,
|
Lazy<ICacheBreakerProvider> cacheBreakProviderFactory,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
: base(diskProvider, cacheBreakProviderFactory, logger)
|
: base(diskProvider, configFileProvider, cacheBreakProviderFactory, logger)
|
||||||
{
|
{
|
||||||
|
_appFolderInfo = appFolderInfo;
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
|
|
||||||
HtmlPath = Path.Combine(appFolderInfo.StartUpFolder, _configFileProvider.UiFolder, "index.html");
|
|
||||||
UrlBase = configFileProvider.UrlBase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
protected override string HtmlPath => Path.Combine(FolderPath, "index.html");
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
return HtmlPath;
|
return HtmlPath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_appFolderInfo = appFolderInfo;
|
_appFolderInfo = appFolderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => _appFolderInfo.GetLogFolder();
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||||
path = Path.GetFileName(path);
|
path = Path.GetFileName(path);
|
||||||
|
|
||||||
return Path.Combine(_appFolderInfo.GetLogFolder(), path);
|
return Path.Combine(FolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanHandle(string resourceUrl)
|
public override bool CanHandle(string resourceUrl)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
{
|
{
|
||||||
public class LoginHtmlMapper : HtmlMapperBase
|
public class LoginHtmlMapper : HtmlMapperBase
|
||||||
{
|
{
|
||||||
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public LoginHtmlMapper(IAppFolderInfo appFolderInfo,
|
public LoginHtmlMapper(IAppFolderInfo appFolderInfo,
|
||||||
@@ -16,14 +17,16 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
Lazy<ICacheBreakerProvider> cacheBreakProviderFactory,
|
Lazy<ICacheBreakerProvider> cacheBreakProviderFactory,
|
||||||
IConfigFileProvider configFileProvider,
|
IConfigFileProvider configFileProvider,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
: base(diskProvider, cacheBreakProviderFactory, logger)
|
: base(diskProvider, configFileProvider, cacheBreakProviderFactory, logger)
|
||||||
{
|
{
|
||||||
|
_appFolderInfo = appFolderInfo;
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
HtmlPath = Path.Combine(appFolderInfo.StartUpFolder, configFileProvider.UiFolder, "login.html");
|
|
||||||
UrlBase = configFileProvider.UrlBase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
protected override string HtmlPath => Path.Combine(FolderPath, "login.html");
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
return HtmlPath;
|
return HtmlPath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
{
|
{
|
||||||
public class ManifestMapper : UrlBaseReplacementResourceMapperBase
|
public class ManifestMapper : UrlBaseReplacementResourceMapperBase
|
||||||
{
|
{
|
||||||
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
private string _generatedContent;
|
private string _generatedContent;
|
||||||
@@ -15,11 +16,14 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
public ManifestMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger)
|
public ManifestMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger)
|
||||||
: base(diskProvider, configFileProvider, logger)
|
: base(diskProvider, configFileProvider, logger)
|
||||||
{
|
{
|
||||||
|
_appFolderInfo = appFolderInfo;
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
FilePath = Path.Combine(appFolderInfo.StartUpFolder, configFileProvider.UiFolder, "Content", "manifest.json");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
protected override string FilePath => Path.Combine(FolderPath, "Content", "manifest.json");
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
return FilePath;
|
return FilePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.GetAppDataPath(), "MediaCover");
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||||
path = path.Trim(Path.DirectorySeparatorChar);
|
path = path.Trim(Path.DirectorySeparatorChar);
|
||||||
|
|||||||
@@ -18,11 +18,13 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var path = Path.Combine("Content", "robots.txt");
|
var path = Path.Combine("Content", "robots.txt");
|
||||||
|
|
||||||
return Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder, path);
|
return Path.Combine(FolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanHandle(string resourceUrl)
|
public override bool CanHandle(string resourceUrl)
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder);
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||||
path = path.Trim(Path.DirectorySeparatorChar);
|
path = path.Trim(Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
return Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder, path);
|
return Path.Combine(FolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanHandle(string resourceUrl)
|
public override bool CanHandle(string resourceUrl)
|
||||||
|
|||||||
@@ -27,14 +27,28 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_caseSensitive = RuntimeInfo.IsProduction ? DiskProviderBase.PathStringComparison : StringComparison.OrdinalIgnoreCase;
|
_caseSensitive = RuntimeInfo.IsProduction ? DiskProviderBase.PathStringComparison : StringComparison.OrdinalIgnoreCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract string Map(string resourceUrl);
|
protected abstract string FolderPath { get; }
|
||||||
|
protected abstract string MapPath(string resourceUrl);
|
||||||
|
|
||||||
public abstract bool CanHandle(string resourceUrl);
|
public abstract bool CanHandle(string resourceUrl);
|
||||||
|
|
||||||
|
public string Map(string resourceUrl)
|
||||||
|
{
|
||||||
|
var filePath = Path.GetFullPath(MapPath(resourceUrl));
|
||||||
|
var parentPath = Path.GetFullPath(FolderPath) + Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
|
return filePath.StartsWith(parentPath) ? filePath : null;
|
||||||
|
}
|
||||||
|
|
||||||
public Task<IActionResult> GetResponse(string resourceUrl)
|
public Task<IActionResult> GetResponse(string resourceUrl)
|
||||||
{
|
{
|
||||||
var filePath = Map(resourceUrl);
|
var filePath = Map(resourceUrl);
|
||||||
|
|
||||||
|
if (filePath == null)
|
||||||
|
{
|
||||||
|
return Task.FromResult<IActionResult>(null);
|
||||||
|
}
|
||||||
|
|
||||||
if (_diskProvider.FileExists(filePath, _caseSensitive))
|
if (_diskProvider.FileExists(filePath, _caseSensitive))
|
||||||
{
|
{
|
||||||
if (!_mimeTypeProvider.TryGetContentType(filePath, out var contentType))
|
if (!_mimeTypeProvider.TryGetContentType(filePath, out var contentType))
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_appFolderInfo = appFolderInfo;
|
_appFolderInfo = appFolderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string FolderPath => _appFolderInfo.GetUpdateLogFolder();
|
||||||
|
|
||||||
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||||
path = Path.GetFileName(path);
|
path = Path.GetFileName(path);
|
||||||
|
|
||||||
return Path.Combine(_appFolderInfo.GetUpdateLogFolder(), path);
|
return Path.Combine(FolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanHandle(string resourceUrl)
|
public override bool CanHandle(string resourceUrl)
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ namespace Sonarr.Http.Frontend.Mappers
|
|||||||
_urlBase = configFileProvider.UrlBase;
|
_urlBase = configFileProvider.UrlBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string FilePath;
|
protected abstract string FilePath { get; }
|
||||||
|
|
||||||
public override string Map(string resourceUrl)
|
protected override string MapPath(string resourceUrl)
|
||||||
{
|
{
|
||||||
return FilePath;
|
return FilePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
@@ -16,6 +17,7 @@ namespace Sonarr.Http.Frontend
|
|||||||
{
|
{
|
||||||
private readonly IEnumerable<IMapHttpRequestsToDisk> _requestMappers;
|
private readonly IEnumerable<IMapHttpRequestsToDisk> _requestMappers;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
private static readonly Regex InvalidPathRegex = new (@"([\/\\]|%2f|%5c)\.\.|\.\.([\/\\]|%2f|%5c)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
public StaticResourceController(IEnumerable<IMapHttpRequestsToDisk> requestMappers,
|
public StaticResourceController(IEnumerable<IMapHttpRequestsToDisk> requestMappers,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
@@ -50,6 +52,11 @@ namespace Sonarr.Http.Frontend
|
|||||||
{
|
{
|
||||||
path = "/" + (path ?? "");
|
path = "/" + (path ?? "");
|
||||||
|
|
||||||
|
if (InvalidPathRegex.IsMatch(path))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path));
|
var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path));
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user