Remove DB and Directory settings out of the BTCPayServerOptions (#2168)

This commit is contained in:
Nicolas Dorier
2020-12-27 22:06:00 +09:00
committed by GitHub
parent 0dcd834535
commit a6ee64ea63
11 changed files with 126 additions and 123 deletions

View File

@@ -14,24 +14,14 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage
public class
FileSystemFileProviderService : BaseTwentyTwentyStorageFileProviderServiceBase<FileSystemStorageConfiguration>
{
private readonly BTCPayServerOptions _options;
private readonly DataDirectories _datadirs;
public FileSystemFileProviderService(BTCPayServerOptions options)
public FileSystemFileProviderService(DataDirectories datadirs)
{
_options = options;
_datadirs = datadirs;
}
public const string LocalStorageDirectoryName = "LocalStorage";
public static string GetStorageDir(BTCPayServerOptions options)
{
return Path.Combine(options.DataDir, LocalStorageDirectoryName);
}
public static string GetTempStorageDir(BTCPayServerOptions options)
{
return Path.Combine(GetStorageDir(options), "tmp");
}
public override StorageProvider StorageProvider()
{
return Storage.Models.StorageProvider.FileSystem;
@@ -40,14 +30,14 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage
protected override Task<IStorageProvider> GetStorageProvider(FileSystemStorageConfiguration configuration)
{
return Task.FromResult<IStorageProvider>(
new LocalStorageProvider(new DirectoryInfo(GetStorageDir(_options)).FullName));
new LocalStorageProvider(new DirectoryInfo(_datadirs.StorageDir).FullName));
}
public override async Task<string> GetFileUrl(Uri baseUri, StoredFile storedFile, StorageSettings configuration)
{
var baseResult = await base.GetFileUrl(baseUri, storedFile, configuration);
var url = new Uri(baseUri, LocalStorageDirectoryName);
return baseResult.Replace(new DirectoryInfo(GetStorageDir(_options)).FullName, url.AbsoluteUri,
return baseResult.Replace(new DirectoryInfo(_datadirs.StorageDir).FullName, url.AbsoluteUri,
StringComparison.InvariantCultureIgnoreCase);
}
@@ -63,13 +53,13 @@ namespace BTCPayServer.Storage.Services.Providers.FileSystemStorage
IsDownload = isDownload
};
var name = Guid.NewGuid().ToString();
var fullPath = Path.Combine(GetTempStorageDir(_options), name);
var fullPath = Path.Combine(_datadirs.TempStorageDir, name);
if (!File.Exists(fullPath))
{
File.Create(fullPath).Dispose();
}
await File.WriteAllTextAsync(Path.Combine(GetTempStorageDir(_options), name), JsonConvert.SerializeObject(localFileDescriptor));
await File.WriteAllTextAsync(Path.Combine(_datadirs.TempStorageDir, name), JsonConvert.SerializeObject(localFileDescriptor));
return new Uri(baseUri, $"{LocalStorageDirectoryName}tmp/{name}{(isDownload ? "?download" : string.Empty)}").AbsoluteUri;
}