diff --git a/BTCPayServer.Abstractions/Contracts/IFileService.cs b/BTCPayServer.Abstractions/Contracts/IFileService.cs new file mode 100644 index 000000000..f1565591f --- /dev/null +++ b/BTCPayServer.Abstractions/Contracts/IFileService.cs @@ -0,0 +1,16 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace BTCPayServer.Abstractions.Contracts; + +public interface IFileService +{ + Task AddFile(IFormFile file, string userId); + Task GetFileUrl(Uri baseUri, string fileId); + + Task GetTemporaryFileUrl(Uri baseUri, string fileId, DateTimeOffset expiry, + bool isDownload); + + Task RemoveFile(string fileId, string userId); +} diff --git a/BTCPayServer.Abstractions/Contracts/IStoredFile.cs b/BTCPayServer.Abstractions/Contracts/IStoredFile.cs new file mode 100644 index 000000000..71ab7131b --- /dev/null +++ b/BTCPayServer.Abstractions/Contracts/IStoredFile.cs @@ -0,0 +1,12 @@ +using System; + +namespace BTCPayServer.Abstractions.Contracts; + +public interface IStoredFile +{ + string Id { get; set; } + string FileName { get; set; } + string StorageFileName { get; set; } + DateTime Timestamp { get; set; } + string ApplicationUserId { get; set; } +} diff --git a/BTCPayServer.Data/Data/StoredFile.cs b/BTCPayServer.Data/Data/StoredFile.cs index b3d603043..15f272dbf 100644 --- a/BTCPayServer.Data/Data/StoredFile.cs +++ b/BTCPayServer.Data/Data/StoredFile.cs @@ -1,9 +1,10 @@ using System; using System.ComponentModel.DataAnnotations.Schema; +using BTCPayServer.Abstractions.Contracts; namespace BTCPayServer.Data { - public class StoredFile + public class StoredFile : IStoredFile { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string Id { get; set; } diff --git a/BTCPayServer/Storage/Services/FileService.cs b/BTCPayServer/Storage/Services/FileService.cs index 3a9925353..d69599e08 100644 --- a/BTCPayServer/Storage/Services/FileService.cs +++ b/BTCPayServer/Storage/Services/FileService.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Data; using BTCPayServer.Services; using BTCPayServer.Storage.Models; @@ -11,7 +12,7 @@ using Microsoft.AspNetCore.Http; namespace BTCPayServer.Storage.Services { - public class FileService + public class FileService : IFileService { private readonly StoredFileRepository _FileRepository; private readonly IEnumerable _providers; @@ -25,7 +26,7 @@ namespace BTCPayServer.Storage.Services _SettingsRepository = settingsRepository; } - public async Task AddFile(IFormFile file, string userId) + public async Task AddFile(IFormFile file, string userId) { var settings = await _SettingsRepository.GetSettingAsync(); if (settings is null) diff --git a/BTCPayServer/Storage/StorageExtensions.cs b/BTCPayServer/Storage/StorageExtensions.cs index 3ac61395f..9e39091b0 100644 --- a/BTCPayServer/Storage/StorageExtensions.cs +++ b/BTCPayServer/Storage/StorageExtensions.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Runtime.InteropServices.ComTypes; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Configuration; using BTCPayServer.Storage.Services; using BTCPayServer.Storage.Services.Providers; @@ -23,6 +24,7 @@ namespace BTCPayServer.Storage { serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(provider => provider.GetRequiredService()); // serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton();