2022-06-02 00:53:57 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-10-27 17:31:29 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
|
|
|
|
namespace Selector.Web
|
|
|
|
|
{
|
2021-10-27 23:00:01 +01:00
|
|
|
|
static class OptionsHelper {
|
2021-10-27 17:31:29 +01:00
|
|
|
|
public static void ConfigureOptions(RootOptions options, IConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
config.GetSection(RootOptions.Key).Bind(options);
|
2021-10-27 23:00:01 +01:00
|
|
|
|
config.GetSection(FormatKeys(new[] { RootOptions.Key, RedisOptions.Key })).Bind(options.RedisOptions);
|
2022-06-02 00:53:57 +01:00
|
|
|
|
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);
|
2021-10-27 23:00:01 +01:00
|
|
|
|
}
|
2021-10-27 17:31:29 +01:00
|
|
|
|
|
|
|
|
|
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; }
|
2021-11-30 20:38:26 +00:00
|
|
|
|
public string LastfmClient { get; set; }
|
|
|
|
|
public string LastfmSecret { get; set; }
|
2021-10-27 23:00:01 +01:00
|
|
|
|
|
2022-09-29 20:37:06 +01:00
|
|
|
|
public TimeSpan CookieExpiry { get; set; } = TimeSpan.FromDays(30);
|
|
|
|
|
|
2021-10-27 23:00:01 +01:00
|
|
|
|
public RedisOptions RedisOptions { get; set; } = new();
|
2022-06-02 00:53:57 +01:00
|
|
|
|
public NowPlayingOptions NowOptions { get; set; } = new();
|
2022-10-10 11:44:47 +01:00
|
|
|
|
public PastOptions PastOptions { get; set; } = new();
|
2021-10-27 23:00:01 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RedisOptions
|
|
|
|
|
{
|
|
|
|
|
public const string Key = "Redis";
|
|
|
|
|
|
|
|
|
|
public bool Enabled { get; set; } = false;
|
|
|
|
|
public string ConnectionString { get; set; }
|
2021-10-27 17:31:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|