Fix import: infer phone when missing
This commit is contained in:
1 parent
59e39789a3
commit
98343906f9
2 files changed
+22
-3
No files matched your search
@@ -347,7 +347,10 @@ public class AccountImportService
|
||||
return new ImportResult(false, null, null, null, null, $"json 缺少 api_hash: {jsonPath}");
|
||||
|
||||
if (!TryGetString(root, out var phone, "phone", "phone_number", "phoneNumber") || string.IsNullOrWhiteSpace(phone))
|
||||
return new ImportResult(false, null, null, null, null, $"json 缺少 phone: {jsonPath}");
|
||||
{
|
||||
if (!TryInferPhone(root, jsonPath, out phone))
|
||||
return new ImportResult(false, null, null, null, null, $"json 缺少 phone: {jsonPath}");
|
||||
}
|
||||
|
||||
phone = PhoneNumberFormatter.NormalizeToDigits(phone);
|
||||
if (string.IsNullOrWhiteSpace(phone))
|
||||
@@ -513,6 +516,16 @@ public class AccountImportService
|
||||
return string.IsNullOrWhiteSpace(username) ? null : username.Trim();
|
||||
}
|
||||
|
||||
private static bool TryInferPhone(System.Text.Json.JsonElement root, string jsonPath, out string? phone)
|
||||
{
|
||||
// 兼容一些导出:json 里 phone 可能为 null,但文件名/ session_file 会带 +手机号
|
||||
if (!TryGetString(root, out phone, "session_file", "sessionFile") || string.IsNullOrWhiteSpace(phone))
|
||||
phone = Path.GetFileNameWithoutExtension(jsonPath);
|
||||
|
||||
phone = string.IsNullOrWhiteSpace(phone) ? null : phone.Trim();
|
||||
return !string.IsNullOrWhiteSpace(phone);
|
||||
}
|
||||
|
||||
private static bool LooksLikeSqliteSession(string filePath)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -72,8 +72,14 @@ if (args.Length >= 2 && string.Equals(args[0], "--diag-session-dir", StringCompa
|
||||
|
||||
if (!TryGetString(root, out var phone, "phone") || string.IsNullOrWhiteSpace(phone))
|
||||
{
|
||||
Console.WriteLine($"[FAIL] {Path.GetFileName(jsonPath)}: 缺少 phone");
|
||||
continue;
|
||||
if (!TryGetString(root, out phone, "session_file", "sessionFile") || string.IsNullOrWhiteSpace(phone))
|
||||
phone = Path.GetFileNameWithoutExtension(jsonPath);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(phone))
|
||||
{
|
||||
Console.WriteLine($"[FAIL] {Path.GetFileName(jsonPath)}: 缺少 phone");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
_ = TryGetLong(root, out var userId, "user_id", "uid");
|
||||
|
||||
Reference in new issue
Block a user