diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index 77e4d8ebc..41dc69369 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -19,6 +19,8 @@ using BTCPayServer.Plugins.PointOfSale.Models; using BTCPayServer.Services; using BTCPayServer.Services.Apps; using BTCPayServer.Services.Stores; +using BTCPayServer.Storage.Models; +using BTCPayServer.Storage.Services.Providers.FileSystemStorage.Configuration; using ExchangeSharp; using Fido2NetLib.Objects; using Microsoft.AspNetCore.Identity; @@ -87,13 +89,15 @@ namespace BTCPayServer.Hosting var settings = (await _Settings.GetSettingAsync()); if (settings is null) { - // If it is null, then it's the first run: let's skip all the migrations by migration flags to true + // If it is null, then it's the first run: let's skip all the migrations by setting flags to true settings = new MigrationSettings() { MigratedInvoiceTextSearchPages = int.MaxValue, MigratedTransactionLabels = int.MaxValue }; foreach (var prop in settings.GetType().GetProperties().Where(p => p.CanWrite && p.PropertyType == typeof(bool))) { prop.SetValue(settings, true); } + // Ensure these checks still get run settings.CheckedFirstRun = false; + settings.FileSystemStorageAsDefault = false; await _Settings.UpdateSetting(settings); } @@ -222,6 +226,21 @@ namespace BTCPayServer.Hosting settings.MigrateWalletColors = true; await _Settings.UpdateSetting(settings); } + if (!settings.FileSystemStorageAsDefault) + { + var storageSettings = await _Settings.GetSettingAsync(); + if (storageSettings is null) + { + storageSettings = new StorageSettings + { + Provider = StorageProvider.FileSystem, + Configuration = JObject.FromObject(new FileSystemStorageConfiguration()) + }; + await _Settings.UpdateSetting(storageSettings); + } + settings.FileSystemStorageAsDefault = true; + await _Settings.UpdateSetting(settings); + } } catch (Exception ex) { diff --git a/BTCPayServer/Services/MigrationSettings.cs b/BTCPayServer/Services/MigrationSettings.cs index e894f00a3..b0877d09a 100644 --- a/BTCPayServer/Services/MigrationSettings.cs +++ b/BTCPayServer/Services/MigrationSettings.cs @@ -34,5 +34,6 @@ namespace BTCPayServer.Services public bool AddStoreToPayout { get; set; } public bool MigrateEmailServerDisableTLSCerts { get; set; } public bool MigrateWalletColors { get; set; } + public bool FileSystemStorageAsDefault { get; set; } } } diff --git a/BTCPayServer/Storage/StorageExtensions.cs b/BTCPayServer/Storage/StorageExtensions.cs index 7900a93d7..fad4e4021 100644 --- a/BTCPayServer/Storage/StorageExtensions.cs +++ b/BTCPayServer/Storage/StorageExtensions.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Runtime.InteropServices.ComTypes; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Configuration; using BTCPayServer.Storage.Services; @@ -25,49 +24,35 @@ namespace BTCPayServer.Storage serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(provider => provider.GetRequiredService()); - // serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); - // serviceCollection.AddSingleton(); } public static void UseProviderStorage(this IApplicationBuilder builder, IOptions datadirs) { try { - DirectoryInfo dirInfo; - if (!Directory.Exists(datadirs.Value.StorageDir)) - { - dirInfo = Directory.CreateDirectory(datadirs.Value.StorageDir); - } - else - { - dirInfo = new DirectoryInfo(datadirs.Value.StorageDir); - } + var dirInfo = Directory.Exists(datadirs.Value.StorageDir) + ? new DirectoryInfo(datadirs.Value.StorageDir) + : Directory.CreateDirectory(datadirs.Value.StorageDir); if (!Directory.Exists(datadirs.Value.TempDir)) { Directory.CreateDirectory(datadirs.Value.TempDir); } - DirectoryInfo tmpdirInfo; - if (!Directory.Exists(datadirs.Value.TempStorageDir)) - { - tmpdirInfo = Directory.CreateDirectory(datadirs.Value.TempStorageDir); - } - else - { - tmpdirInfo = new DirectoryInfo(datadirs.Value.TempStorageDir); - } + var tmpdirInfo = Directory.Exists(datadirs.Value.TempStorageDir) + ? new DirectoryInfo(datadirs.Value.TempStorageDir) + : Directory.CreateDirectory(datadirs.Value.TempStorageDir); - builder.UseStaticFiles(new StaticFileOptions() + builder.UseStaticFiles(new StaticFileOptions { ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}"), FileProvider = new PhysicalFileProvider(dirInfo.FullName), OnPrepareResponse = HandleStaticFileResponse() }); - builder.UseStaticFiles(new StaticFileOptions() + builder.UseStaticFiles(new StaticFileOptions { ServeUnknownFileTypes = true, RequestPath = new PathString($"/{FileSystemFileProviderService.LocalStorageDirectoryName}tmp"), @@ -78,7 +63,7 @@ namespace BTCPayServer.Storage } catch (Exception e) { - Logs.Utils.LogError(e, $"Could not initialize the Local File Storage system(uploading and storing files locally)"); + Logs.Utils.LogError(e, "Could not initialize the Local File Storage system (for uploading and storing files locally)"); } }