// Copyright (c) Umbraco. // See LICENSE for more details. using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders.Physical; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; namespace Umbraco.Cms.Web.Common.Plugins; /// /// Looks up files using the on-disk file system and check file extensions are on a allow list /// /// /// When the environment variable "DOTNET_USE_POLLING_FILE_WATCHER" is set to "1" or "true", calls to /// will use . /// public class UmbracoPluginPhysicalFileProvider : PhysicalFileProvider, IFileProvider { private UmbracoPluginSettings _options; /// /// Initializes a new instance of the class, at the given root /// directory. /// /// The root directory. This should be an absolute path. /// The configuration options. /// Specifies which files or directories are excluded. public UmbracoPluginPhysicalFileProvider(string root, IOptionsMonitor options, ExclusionFilters filters = ExclusionFilters.Sensitive) : base(root, filters) { _options = options.CurrentValue; options.OnChange(x => { _options = x; }); } /// /// Locate a file at the given path by directly mapping path segments to physical directories. /// /// /// The path needs to pass the and the /// to be found. /// /// A path under the root directory /// The file information. Caller must check property. public new IFileInfo GetFileInfo(string subpath) { var extension = Path.GetExtension(subpath); var subPathInclAppPluginsFolder = Path.Combine(Core.Constants.SystemDirectories.AppPlugins, subpath); if (!_options.BrowsableFileExtensions.Contains(extension)) { return new NotFoundFileInfo(subPathInclAppPluginsFolder); } return base.GetFileInfo(subPathInclAppPluginsFolder); } }