write thumbnail to wallet store
This commit is contained in:
+28
-8
@@ -1,18 +1,38 @@
|
||||
using Toolkit.Foundation;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Text;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class WalletFactory(IComponentFactory componentFactory) :
|
||||
public class WalletFactory(ISecurityKeyFactory securityKeyFactory,
|
||||
IDecoratorService<SecurityKey> secureKeyStore,
|
||||
IWalletStoreFactory walletStoreFactory,
|
||||
IWritableConfiguration<WalletConfiguration> configuration,
|
||||
IHostEnvironment environment,
|
||||
IImageWriter imageWriter) :
|
||||
IWalletFactory
|
||||
{
|
||||
public IComponentHost? Create(string key)
|
||||
public async Task<bool> Create(string name,
|
||||
string password,
|
||||
IImageDescriptor thumbnail)
|
||||
{
|
||||
if (componentFactory.Create<WalletComponent, WalletConfiguration>($"Wallet:{key}",
|
||||
new WalletConfiguration()) is IComponentHost host)
|
||||
if (securityKeyFactory.Create(Encoding.UTF8.GetBytes(password)) is SecurityKey key)
|
||||
{
|
||||
return host;
|
||||
secureKeyStore.Set(key);
|
||||
|
||||
if (await walletStoreFactory.Create(name, key))
|
||||
{
|
||||
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:" +
|
||||
$"{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
||||
|
||||
string file = Path.Combine(environment.ContentRootPath, "Thumbnail.png");
|
||||
using FileStream stream = File.OpenWrite(file);
|
||||
|
||||
imageWriter.Write(thumbnail, stream);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user