refactor(agent): remove obsolete compatibility paths
This commit is contained in:
@@ -216,7 +216,7 @@ try
|
||||
await WechatChatClient.CloseSubWindowAsync("文件传输助手", cancellationToken);
|
||||
var contacts = await WechatChatClient.GetFriendsAsync(5000, cancellationToken);
|
||||
var newFriends = await WechatChatClient.GetNewFriendsAsync(true, cancellationToken);
|
||||
var groups = await WechatChatClient.GetRecentGroupsAsync(cancellationToken);
|
||||
var groups = await WechatChatClient.GetContactsPageAsync(limit: 200, groupsOnly: true, cancellationToken: cancellationToken);
|
||||
var myInfo = await WechatChatClient.GetMyInfoAsync(cancellationToken);
|
||||
await WechatChatClient.SwitchToChatsAsync(cancellationToken);
|
||||
var confirmationGuarded = false;
|
||||
@@ -236,7 +236,7 @@ try
|
||||
historyCount = history.Count,
|
||||
contactCount = contacts.Count,
|
||||
newFriendCount = newFriends.Count,
|
||||
recentGroupCount = groups.Count,
|
||||
groupPageCount = groups.Contacts.Count,
|
||||
accountDetected = !string.IsNullOrWhiteSpace(myInfo.DisplayName),
|
||||
confirmationGuarded,
|
||||
privacy = "names and account identifiers omitted"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Net.Http;
|
||||
using WxAgent.Core;
|
||||
|
||||
namespace WxAgent.Host;
|
||||
@@ -17,19 +16,10 @@ internal static class RemoteCliCommands
|
||||
return (group, action) switch
|
||||
{
|
||||
("auth", "show") => await AuthShowAsync(configPath, cancellationToken),
|
||||
("auth", "set") => await AuthSetAsync(args, configPath, cancellationToken),
|
||||
("auth", "clear") => await AuthClearAsync(configPath, cancellationToken),
|
||||
("probe", "run") => await ProbeAsync(configPath, cancellationToken),
|
||||
("status", "show") => await StatusShowAsync(args, configPath, cancellationToken),
|
||||
("reporting", "show") => await ReportingShowAsync(configPath, cancellationToken),
|
||||
("reporting", "enable") => await ReportingToggleAsync(configPath, true, cancellationToken),
|
||||
("reporting", "disable") => await ReportingToggleAsync(configPath, false, cancellationToken),
|
||||
("reporting", "account-add") => await AccountToggleAsync(args, configPath, false, cancellationToken),
|
||||
("reporting", "account-enable") => await AccountToggleAsync(args, configPath, true, cancellationToken),
|
||||
("reporting", "account-disable") => await AccountToggleAsync(args, configPath, false, cancellationToken),
|
||||
("reporting", "allow") => await AllowChatAsync(args, configPath, cancellationToken),
|
||||
("reporting", "deny") => await DenyChatAsync(args, configPath, cancellationToken),
|
||||
_ => throw Invalid("Unknown remote command. Use: auth show|set|clear, status show, probe run, reporting show|enable|disable|account-add|account-enable|account-disable|allow|deny.")
|
||||
_ => throw Invalid("Unknown remote command. Use: auth show, status show, probe run, reporting show.")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,34 +35,6 @@ internal static class RemoteCliCommands
|
||||
};
|
||||
}
|
||||
|
||||
private static async Task<object> AuthSetAsync(string[] args, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var current = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
var remote = new RemoteAgentOptions
|
||||
{
|
||||
AuthAddress = Required(args, "--address"),
|
||||
Token = Option(args, "--token"),
|
||||
TokenFile = Option(args, "--token-file"),
|
||||
ServerCaFile = Option(args, "--server-ca-file"),
|
||||
ClientCertificateFile = Option(args, "--client-certificate-file"),
|
||||
ClientCertificateKeyFile = Option(args, "--client-certificate-key-file"),
|
||||
NodeId = Required(args, "--node"),
|
||||
ActiveAccountId = Option(args, "--active-account"),
|
||||
AllowInsecureHttp = Has(args, "--allow-insecure-http")
|
||||
};
|
||||
remote.Validate();
|
||||
var next = (current with { Remote = remote }).WithAudit("remote.auth.set");
|
||||
await RemoteNodeConfigurationStore.SaveAsync(path, next, cancellationToken);
|
||||
return new { saved = path, remote = remote.Redacted() };
|
||||
}
|
||||
|
||||
private static async Task<object> AuthClearAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var current = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
await RemoteNodeConfigurationStore.SaveAsync(path, (current with { Remote = new RemoteAgentOptions() }).WithAudit("remote.auth.clear"), cancellationToken);
|
||||
return new { saved = path, configured = false };
|
||||
}
|
||||
|
||||
private static async Task<object> ProbeAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var configuration = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
@@ -129,72 +91,6 @@ internal static class RemoteCliCommands
|
||||
};
|
||||
}
|
||||
|
||||
private static async Task<object> ReportingToggleAsync(string path, bool enabled, CancellationToken cancellationToken)
|
||||
{
|
||||
var current = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
var reporting = ReportingConfigStore.Update(current.Reporting, value => value with { Enabled = enabled });
|
||||
await RemoteNodeConfigurationStore.SaveAsync(path, (current with { Reporting = reporting }).WithAudit(enabled ? "reporting.enable" : "reporting.disable"), cancellationToken);
|
||||
return new { saved = path, reporting.Enabled, reporting.ConfigVersion };
|
||||
}
|
||||
|
||||
private static async Task<object> AccountToggleAsync(string[] args, string path, bool enabled, CancellationToken cancellationToken)
|
||||
{
|
||||
var accountId = Required(args, "--account");
|
||||
var current = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
var accounts = current.Reporting.Accounts.ToList();
|
||||
var index = accounts.FindIndex(account => string.Equals(account.AccountId, accountId, StringComparison.Ordinal));
|
||||
if (index < 0)
|
||||
{
|
||||
if (args[2] != "account-add") throw Invalid("The account does not exist; run reporting account-add first.");
|
||||
accounts.Add(new AccountReportingConfig { AccountId = accountId, Enabled = enabled });
|
||||
}
|
||||
else
|
||||
{
|
||||
accounts[index] = accounts[index] with { Enabled = enabled };
|
||||
}
|
||||
var reporting = ReportingConfigStore.Update(current.Reporting, value => value with { Accounts = accounts });
|
||||
await RemoteNodeConfigurationStore.SaveAsync(path, (current with { Reporting = reporting }).WithAudit($"reporting.account.{(enabled ? "enable" : "disable")}"), cancellationToken);
|
||||
return new { saved = path, accountId = Mask(accountId), enabled, reporting.ConfigVersion };
|
||||
}
|
||||
|
||||
private static async Task<object> AllowChatAsync(string[] args, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!Has(args, "--identity-verified"))
|
||||
throw Invalid("Allowing a chat requires --identity-verified after the stable identity was confirmed.");
|
||||
var accountId = Required(args, "--account");
|
||||
var chatId = Required(args, "--chat-id");
|
||||
var type = ParseChatType(Required(args, "--type"));
|
||||
var current = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
var accounts = current.Reporting.Accounts.ToList();
|
||||
var index = accounts.FindIndex(account => string.Equals(account.AccountId, accountId, StringComparison.Ordinal));
|
||||
if (index < 0 || !accounts[index].Enabled)
|
||||
throw Invalid("The account must exist and be enabled before a chat can be allowed.");
|
||||
var chats = accounts[index].AllowedChats.Where(chat => chat.Type != type || chat.ChatId != chatId).ToList();
|
||||
chats.Add(new AllowedChat { Type = type, ChatId = chatId, Enabled = true, IdentityVerified = true });
|
||||
accounts[index] = accounts[index] with { AllowedChats = chats };
|
||||
var reporting = ReportingConfigStore.Update(current.Reporting, value => value with { Accounts = accounts });
|
||||
await RemoteNodeConfigurationStore.SaveAsync(path, (current with { Reporting = reporting }).WithAudit("reporting.chat.allow"), cancellationToken);
|
||||
return new { saved = path, accountId = Mask(accountId), chatId = Mask(chatId), type, reporting.ConfigVersion };
|
||||
}
|
||||
|
||||
private static async Task<object> DenyChatAsync(string[] args, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var accountId = Required(args, "--account");
|
||||
var chatId = Required(args, "--chat-id");
|
||||
var type = ParseChatType(Required(args, "--type"));
|
||||
var current = await RemoteNodeConfigurationStore.LoadAsync(path, cancellationToken);
|
||||
var accounts = current.Reporting.Accounts.ToList();
|
||||
var index = accounts.FindIndex(account => string.Equals(account.AccountId, accountId, StringComparison.Ordinal));
|
||||
if (index < 0) throw Invalid("The account does not exist.");
|
||||
accounts[index] = accounts[index] with
|
||||
{
|
||||
AllowedChats = accounts[index].AllowedChats.Where(chat => chat.Type != type || chat.ChatId != chatId).ToArray()
|
||||
};
|
||||
var reporting = ReportingConfigStore.Update(current.Reporting, value => value with { Accounts = accounts });
|
||||
await RemoteNodeConfigurationStore.SaveAsync(path, (current with { Reporting = reporting }).WithAudit("reporting.chat.deny"), cancellationToken);
|
||||
return new { saved = path, accountId = Mask(accountId), chatId = Mask(chatId), type, reporting.ConfigVersion };
|
||||
}
|
||||
|
||||
private static bool IsConfigurationCommand(string[] args) => (args[1], args[2]) switch
|
||||
{
|
||||
("auth", "set" or "clear") => true,
|
||||
@@ -202,13 +98,6 @@ internal static class RemoteCliCommands
|
||||
_ => false
|
||||
};
|
||||
|
||||
private static ReportingChatType ParseChatType(string value) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"group" => ReportingChatType.Group,
|
||||
"private" => ReportingChatType.Private,
|
||||
_ => throw Invalid("--type must be group or private.")
|
||||
};
|
||||
|
||||
private static string Required(string[] args, string name) => Option(args, name) switch
|
||||
{
|
||||
{ Length: > 0 } value => value,
|
||||
|
||||
Reference in New Issue
Block a user