mirror of https://github.com/abpframework/abp.git
5 changed files with 111 additions and 29 deletions
@ -0,0 +1,32 @@ |
|||
using System.IO; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BlobStoring.FileSystem |
|||
{ |
|||
public class DefaultBlogFilePathCalculator : IBlogFilePathCalculator, ITransientDependency |
|||
{ |
|||
public virtual string Calculate(BlobProviderArgs args) |
|||
{ |
|||
var fileSystemConfiguration = args.Configuration.GetFileSystemConfiguration(); |
|||
var blobPath = fileSystemConfiguration.BasePath; |
|||
|
|||
if (args.TenantId == null) |
|||
{ |
|||
blobPath = Path.Combine(blobPath, "host"); |
|||
} |
|||
else |
|||
{ |
|||
blobPath = Path.Combine(blobPath, "tenants", args.TenantId.Value.ToString("D")); |
|||
} |
|||
|
|||
if (fileSystemConfiguration.AppendContainerNameToBasePath) |
|||
{ |
|||
blobPath = Path.Combine(blobPath, args.ContainerName); |
|||
} |
|||
|
|||
blobPath = Path.Combine(blobPath, args.BlobName); |
|||
|
|||
return blobPath; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BlobStoring.FileSystem |
|||
{ |
|||
public interface IBlogFilePathCalculator |
|||
{ |
|||
string Calculate(BlobProviderArgs args); |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
using System; |
|||
using System.IO; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.BlobStoring.FileSystem |
|||
{ |
|||
public class BlogFilePathCalculator_Tests : AbpBlobStoringFileSystemTestBase |
|||
{ |
|||
private readonly IBlogFilePathCalculator _calculator; |
|||
|
|||
public BlogFilePathCalculator_Tests() |
|||
{ |
|||
_calculator = GetRequiredService<IBlogFilePathCalculator>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Default_Settings() |
|||
{ |
|||
var separator = Path.DirectorySeparatorChar; |
|||
|
|||
_calculator.Calculate( |
|||
GetArgs($"C:{separator}my-files","my-container","my-blob") |
|||
).ShouldBe($"C:{separator}my-files{separator}host{separator}my-container{separator}my-blob"); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AppendContainerNameToBasePath_Set_To_False() |
|||
{ |
|||
var separator = Path.DirectorySeparatorChar; |
|||
|
|||
_calculator.Calculate( |
|||
GetArgs($"C:{separator}my-files","my-container","my-blob", appendContainerNameToBasePath: false) |
|||
).ShouldBe($"C:{separator}my-files{separator}host{separator}my-blob"); |
|||
} |
|||
|
|||
private BlobProviderArgs GetArgs( |
|||
string basePath, |
|||
string containerName, |
|||
string blobName, |
|||
Guid? tenantId = null, |
|||
bool? appendContainerNameToBasePath = null) |
|||
{ |
|||
return new BlobProviderGetArgs( |
|||
containerName, |
|||
new BlobContainerConfiguration() |
|||
.UseFileSystem(fs => |
|||
{ |
|||
fs.BasePath = basePath; |
|||
if (appendContainerNameToBasePath.HasValue) |
|||
{ |
|||
fs.AppendContainerNameToBasePath = appendContainerNameToBasePath.Value; |
|||
} |
|||
}), |
|||
blobName, |
|||
tenantId |
|||
); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue