using ErsatzTV.Core; using ErsatzTV.Core.Interfaces.Jellyfin; using ErsatzTV.Core.Jellyfin; using Newtonsoft.Json; namespace ErsatzTV.Infrastructure.Jellyfin; public class JellyfinSecretStore : IJellyfinSecretStore { public Task DeleteAll() => SaveSecrets(new JellyfinSecrets()); public Task ReadSecrets() => File.ReadAllTextAsync(FileSystemLayout.JellyfinSecretsPath) .Map(JsonConvert.DeserializeObject) .Map(s => Optional(s).IfNone(new JellyfinSecrets())); public Task SaveSecrets(JellyfinSecrets secrets) => Some(JsonConvert.SerializeObject(secrets)).Match( s => File.WriteAllTextAsync(FileSystemLayout.JellyfinSecretsPath, s).ToUnit(), Task.FromResult(Unit.Default)); }