Selector/Selector.Web/Options.cs

61 lines
2.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
namespace Selector.Web
{
static class OptionsHelper {
public static void ConfigureOptions(RootOptions options, IConfiguration config)
{
config.GetSection(RootOptions.Key).Bind(options);
config.GetSection(FormatKeys(new[] { RootOptions.Key, RedisOptions.Key })).Bind(options.RedisOptions);
config.GetSection(FormatKeys(new[] { RootOptions.Key, NowPlayingOptions.Key })).Bind(options.NowOptions);
2022-10-10 11:44:47 +01:00
config.GetSection(FormatKeys(new[] { RootOptions.Key, PastOptions.Key })).Bind(options.PastOptions);
}
public static RootOptions ConfigureOptions(IConfiguration config)
{
var options = config.GetSection(RootOptions.Key).Get<RootOptions>();
ConfigureOptions(options, config);
return options;
}
public static string FormatKeys(string[] args) => string.Join(":", args);
}
public class RootOptions
{
public const string Key = "Selector";
/// <summary>
/// Spotify client ID
/// </summary>
public string ClientId { get; set; }
/// <summary>
/// Spotify app secret
/// </summary>
public string ClientSecret { get; set; }
/// <summary>
/// Spotify callback for authentication
/// </summary>
public string SpotifyCallback { get; set; }
public string LastfmClient { get; set; }
public string LastfmSecret { get; set; }
2022-09-29 20:37:06 +01:00
public TimeSpan CookieExpiry { get; set; } = TimeSpan.FromDays(30);
public RedisOptions RedisOptions { get; set; } = new();
public NowPlayingOptions NowOptions { get; set; } = new();
2022-10-10 11:44:47 +01:00
public PastOptions PastOptions { get; set; } = new();
}
public class RedisOptions
{
public const string Key = "Redis";
public bool Enabled { get; set; } = false;
public string ConnectionString { get; set; }
}
}