btcpayserver/BTCPayServer/Storage/StorageExtensions.cs
Andrew Camilleri b184360eb7 Abstracted cloud storage - Amazon/Google/Azure/Local (#708)
* wip

* add in storage system

* ui fixes

* fix settings ui

* Add Files Crud UI

* add titles

* link files to users

* add migration

* set blob to public

* remove base 64 read code

* fix file query model init

* move view model to own file

* fix local root path

* use datadir for local storage

* move to services

* add direct file url

* try fix tests

* remove magic string

* remove other magic strings

* show error message on unsupported provider

* fix asp net version

* redirect to storage settings if provider is not supported

* start writing tests

* fix tests

* fix test again

* add some more to the tests

* more tests

* try making local provider work on tests

* fix formfile

* fix small issue with returning deleted file

* check if returned data is null for deleted file

* validate azure Container name

* more state fixes

* change azure test trait

* add tmp file url generator

* fix tests

* small clean

* disable amazon and  google


comment out unused code for now


comment out google/amazon
2019-04-22 16:41:20 +09:00

50 lines
2 KiB
C#

using System.IO;
using BTCPayServer.Configuration;
using BTCPayServer.Storage.Services;
using BTCPayServer.Storage.Services.Providers;
using BTCPayServer.Storage.Services.Providers.AmazonS3Storage;
using BTCPayServer.Storage.Services.Providers.AzureBlobStorage;
using BTCPayServer.Storage.Services.Providers.FileSystemStorage;
using BTCPayServer.Storage.Services.Providers.GoogleCloudStorage;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
namespace BTCPayServer.Storage
{
public static class StorageExtensions
{
public static void AddProviderStorage(this IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<StoredFileRepository>();
serviceCollection.AddSingleton<FileService>();
// serviceCollection.AddSingleton<IStorageProviderService, AmazonS3FileProviderService>();
serviceCollection.AddSingleton<IStorageProviderService, AzureBlobStorageFileProviderService>();
serviceCollection.AddSingleton<IStorageProviderService, FileSystemFileProviderService>();
// serviceCollection.AddSingleton<IStorageProviderService, GoogleCloudStorageFileProviderService>();
}
public static void UseProviderStorage(this IApplicationBuilder builder, BTCPayServerOptions options)
{
var dir = FileSystemFileProviderService.GetStorageDir(options);
DirectoryInfo dirInfo;
if (!Directory.Exists(dir))
{
dirInfo = Directory.CreateDirectory(dir);
}
else
{
dirInfo = new DirectoryInfo(dir);
}
builder.UseStaticFiles(new StaticFileOptions()
{
ServeUnknownFileTypes = true,
RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"),
FileProvider = new PhysicalFileProvider(dirInfo.FullName)
});
}
}
}