|
|
|
@ -12,6 +12,7 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles
|
|
|
|
|
{
|
|
|
|
|
private readonly Lazy<IEmbeddedFileManager> _embeddedResourceManager;
|
|
|
|
|
private readonly Lazy<AspNetCoreEmbeddedFileOptions> _options;
|
|
|
|
|
private readonly IObjectAccessor<IServiceProvider> _serviceProviderAccessor;
|
|
|
|
|
|
|
|
|
|
public EmbeddedResourceFileProvider(IServiceProvider serviceProvider)
|
|
|
|
|
: this(new ObjectAccessor<IServiceProvider>(serviceProvider))
|
|
|
|
@ -19,21 +20,28 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EmbeddedResourceFileProvider(IObjectAccessor<IServiceProvider> serviceProvider)
|
|
|
|
|
public EmbeddedResourceFileProvider(IObjectAccessor<IServiceProvider> serviceProviderAccessor)
|
|
|
|
|
{
|
|
|
|
|
_serviceProviderAccessor = serviceProviderAccessor;
|
|
|
|
|
|
|
|
|
|
_embeddedResourceManager = new Lazy<IEmbeddedFileManager>(
|
|
|
|
|
() => serviceProvider.Value.GetRequiredService<IEmbeddedFileManager>(),
|
|
|
|
|
() => serviceProviderAccessor.Value.GetRequiredService<IEmbeddedFileManager>(),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_options = new Lazy<AspNetCoreEmbeddedFileOptions>(
|
|
|
|
|
() => serviceProvider.Value.GetRequiredService<IOptions<AspNetCoreEmbeddedFileOptions>>().Value,
|
|
|
|
|
() => serviceProviderAccessor.Value.GetRequiredService<IOptions<AspNetCoreEmbeddedFileOptions>>().Value,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFileInfo GetFileInfo(string subpath)
|
|
|
|
|
{
|
|
|
|
|
if (!IsInitialized())
|
|
|
|
|
{
|
|
|
|
|
return new NotFoundFileInfo(subpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resource = _embeddedResourceManager.Value.FindFile(subpath);
|
|
|
|
|
|
|
|
|
|
if (resource == null || IsIgnoredFile(resource))
|
|
|
|
@ -46,6 +54,11 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles
|
|
|
|
|
|
|
|
|
|
public IDirectoryContents GetDirectoryContents(string subpath)
|
|
|
|
|
{
|
|
|
|
|
if (!IsInitialized())
|
|
|
|
|
{
|
|
|
|
|
return new NotFoundDirectoryContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: Implement...?
|
|
|
|
|
|
|
|
|
|
return new NotFoundDirectoryContents();
|
|
|
|
@ -60,5 +73,10 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles
|
|
|
|
|
{
|
|
|
|
|
return resource.FileExtension != null && _options.Value.IgnoredFileExtensions.Contains(resource.FileExtension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsInitialized()
|
|
|
|
|
{
|
|
|
|
|
return _serviceProviderAccessor.Value != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|