aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/ResourceFileManager.cs
diff options
context:
space:
mode:
authorstefan <stefan@hegedues.at>2018-09-12 19:26:21 +0200
committerstefan <stefan@hegedues.at>2018-09-12 19:26:21 +0200
commit48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch)
tree8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Server.Implementations/ResourceFileManager.cs
parentc32d8656382a0eacb301692e0084377fc433ae9b (diff)
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Server.Implementations/ResourceFileManager.cs')
-rw-r--r--Emby.Server.Implementations/ResourceFileManager.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/ResourceFileManager.cs b/Emby.Server.Implementations/ResourceFileManager.cs
new file mode 100644
index 000000000..ce29b52f6
--- /dev/null
+++ b/Emby.Server.Implementations/ResourceFileManager.cs
@@ -0,0 +1,74 @@
+using MediaBrowser.Common.Extensions;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Controller.Plugins;
+using MediaBrowser.Model.Extensions;
+using MediaBrowser.Model.Logging;
+using MediaBrowser.Model.Net;
+using MediaBrowser.Model.Serialization;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Plugins;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.Plugins;
+using MediaBrowser.Model.Reflection;
+using MediaBrowser.Model.Services;
+
+namespace Emby.Server.Implementations
+{
+ public class ResourceFileManager : IResourceFileManager
+ {
+ private readonly IFileSystem _fileSystem;
+ private readonly ILogger _logger;
+ private readonly IHttpResultFactory _resultFactory;
+
+ public ResourceFileManager(IHttpResultFactory resultFactory, ILogger logger, IFileSystem fileSystem)
+ {
+ _resultFactory = resultFactory;
+ _logger = logger;
+ _fileSystem = fileSystem;
+ }
+
+ public Stream GetResourceFileStream(string basePath, string virtualPath)
+ {
+ return _fileSystem.GetFileStream(GetResourcePath(basePath, virtualPath), FileOpenMode.Open, FileAccessMode.Read, FileShareMode.ReadWrite, true);
+ }
+
+ public Task<object> GetStaticFileResult(IRequest request, string basePath, string virtualPath, string contentType, TimeSpan? cacheDuration)
+ {
+ return _resultFactory.GetStaticFileResult(request, GetResourcePath(basePath, virtualPath));
+ }
+
+ public string ReadAllText(string basePath, string virtualPath)
+ {
+ return _fileSystem.ReadAllText(GetResourcePath(basePath, virtualPath));
+ }
+
+ private string GetResourcePath(string basePath, string virtualPath)
+ {
+ var fullPath = Path.Combine(basePath, virtualPath.Replace('/', _fileSystem.DirectorySeparatorChar));
+
+ try
+ {
+ fullPath = _fileSystem.GetFullPath(fullPath);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error in Path.GetFullPath", ex);
+ }
+
+ // Don't allow file system access outside of the source folder
+ if (!_fileSystem.ContainsSubPath(basePath, fullPath))
+ {
+ throw new SecurityException("Access denied");
+ }
+
+ return fullPath;
+ }
+ }
+}