feat: 新增 textValue 支持结构化字段内容展示

This commit is contained in:
tigerenwork 2026-07-26 22:33:54 +08:00
parent 55d0f86392
commit 88f89cc918
1 changed files with 23 additions and 8 deletions

View File

@ -96,6 +96,26 @@ enum JSONValue: Decodable {
return nil
}
/// Display text for Feishu fields whose values are represented as
/// structured content, such as text fields (`[{"type": "text", "text": "..."}]`).
var textValue: String? {
switch self {
case let .string(value):
return value
case let .number(value):
return String(value)
case let .bool(value):
return String(value)
case let .array(items):
let text = items.compactMap(\.textValue).joined()
return text.isEmpty ? nil : text
case let .object(fields):
return fields["text"]?.textValue ?? fields["name"]?.textValue
case .null:
return nil
}
}
var firstUserName: String? {
guard case let .array(items) = self else { return nil }
for item in items {
@ -142,21 +162,16 @@ enum BugMapper {
case let .number(number): return number
case let .bool(bool): return bool
case let .array(array):
return array.compactMap { item -> String? in
if case let .object(fields) = item {
return fields["name"]?.stringValue
}
return item.stringValue
}
return array.compactMap(\.textValue)
case let .object(object):
return object["name"]?.stringValue ?? object["text"]?.stringValue
return object["name"]?.textValue ?? object["text"]?.textValue
case .null:
return nil
}
}
private static func stringValue(in fields: [String: JSONValue], key: String) -> String? {
fields[key]?.stringValue
fields[key]?.textValue
}
private static func userName(in fields: [String: JSONValue], key: String) -> String? {