mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-04 18:06:08 +01:00
Allow file service to be used in plugins
This commit is contained in:
parent
03e49ea2bf
commit
3231d5d179
5 changed files with 35 additions and 3 deletions
16
BTCPayServer.Abstractions/Contracts/IFileService.cs
Normal file
16
BTCPayServer.Abstractions/Contracts/IFileService.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace BTCPayServer.Abstractions.Contracts;
|
||||
|
||||
public interface IFileService
|
||||
{
|
||||
Task<IStoredFile> AddFile(IFormFile file, string userId);
|
||||
Task<string?> GetFileUrl(Uri baseUri, string fileId);
|
||||
|
||||
Task<string?> GetTemporaryFileUrl(Uri baseUri, string fileId, DateTimeOffset expiry,
|
||||
bool isDownload);
|
||||
|
||||
Task RemoveFile(string fileId, string userId);
|
||||
}
|
12
BTCPayServer.Abstractions/Contracts/IStoredFile.cs
Normal file
12
BTCPayServer.Abstractions/Contracts/IStoredFile.cs
Normal file
|
@ -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; }
|
||||
}
|
|
@ -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; }
|
||||
|
|
|
@ -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<IStorageProviderService> _providers;
|
||||
|
@ -25,7 +26,7 @@ namespace BTCPayServer.Storage.Services
|
|||
_SettingsRepository = settingsRepository;
|
||||
}
|
||||
|
||||
public async Task<StoredFile> AddFile(IFormFile file, string userId)
|
||||
public async Task<IStoredFile> AddFile(IFormFile file, string userId)
|
||||
{
|
||||
var settings = await _SettingsRepository.GetSettingAsync<StorageSettings>();
|
||||
if (settings is null)
|
||||
|
|
|
@ -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<StoredFileRepository>();
|
||||
serviceCollection.AddSingleton<FileService>();
|
||||
serviceCollection.AddSingleton<IFileService>(provider => provider.GetRequiredService<FileService>());
|
||||
// serviceCollection.AddSingleton<IStorageProviderService, AmazonS3FileProviderService>();
|
||||
serviceCollection.AddSingleton<IStorageProviderService, AzureBlobStorageFileProviderService>();
|
||||
serviceCollection.AddSingleton<IStorageProviderService, FileSystemFileProviderService>();
|
||||
|
|
Loading…
Add table
Reference in a new issue