Newsbot.Cli/Newsbot.Services/Config/SetInstanceService.cs

25 lines
663 B
C#

using jtom38.Newsbot.Domain.Models;
namespace jtom38.Newsbot.Services.Config;
public class SetInstanceService
{
public static async Task Save(string uri)
{
var containsHttp = uri.Contains("http://");
var containsHttps = uri.Contains("https://");
if (!containsHttp && !containsHttps)
{
throw new Exception("Uri does not define http or https.");
}
Console.WriteLine($"Instance Set to '{uri}'");
var cfg = await ConfigClient.LoadAsync();
cfg ??= new ConfigModel();
cfg.Uri = uri ?? "";
await ConfigClient.SaveAsync(cfg);
}
}