initial commit

This commit is contained in:
Kukks
2023-01-16 10:31:48 +01:00
parent 136273406c
commit 25ccd99558
171 changed files with 10592 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
using System;
using System.IO;
using System.Threading.Tasks;
using BTCPayServer.Configuration;
using BTCPayServer.Plugins.LiquidPlus.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Plugins.LiquidPlus.Services
{
public class CustomLiquidAssetsRepository
{
private readonly ILogger<CustomLiquidAssetsRepository> _logger;
private readonly IOptions<DataDirectories> _options;
private string File => Path.Combine(_options.Value.DataDir, "custom-liquid-assets.json");
public CustomLiquidAssetsRepository(ILogger<CustomLiquidAssetsRepository> logger, IOptions<DataDirectories> options)
{
_logger = logger;
_options = options;
}
public CustomLiquidAssetsSettings Get()
{
try
{
if (System.IO.File.Exists(File))
{
return JObject.Parse(System.IO.File.ReadAllText(File)).ToObject<CustomLiquidAssetsSettings>();
}
}
catch (Exception e)
{
_logger.LogError(e, "could not parse custom liquid assets file");
}
return new CustomLiquidAssetsSettings();
}
public async Task Set(CustomLiquidAssetsSettings settings)
{
try
{
await System.IO.File.WriteAllTextAsync(File, JObject.FromObject(settings).ToString(Formatting.Indented));
ChangesPending = true;
}
catch (Exception e)
{
_logger.LogError(e, "could not write custom liquid assets file");
}
}
public bool ChangesPending { get; private set; }
}
}