refactor(sns): parse_post_xml dedup 两份 ParsedPost 早 return 块

merge 前自查发现 Document::parse 失败 / 找不到 TimelineObject 两条
fallback 路径写了完全相同的 9 行 ParsedPost 字面量。抽成 empty()
闭包,从 2×9 行降到 1×7 行 + 两个 return empty()。

行为完全等价(含 author = column fallback)。
pull/17/head
jackwener 2026-04-19 13:45:44 +08:00
parent d1b1f58d41
commit 45e6bc05db
1 changed files with 9 additions and 19 deletions

View File

@ -1770,28 +1770,18 @@ struct ParsedPost {
/// 旧版 `extract_xml_text` 是字符串扫描不解码 —— 因此 `content` / `location` / `username` 字段
/// 现在会输出解码后的文本,对下游是更正确的语义。
fn parse_post_xml(tid: i64, user_name_column: &str, content: &str) -> ParsedPost {
let fallback_author = || user_name_column.to_string();
let Ok(doc) = Document::parse(content) else {
return ParsedPost {
tid,
create_time: 0,
author_username: fallback_author(),
content: String::new(),
media: Vec::new(),
location: String::new(),
};
let empty = || ParsedPost {
tid,
create_time: 0,
author_username: user_name_column.to_string(),
content: String::new(),
media: Vec::new(),
location: String::new(),
};
let Ok(doc) = Document::parse(content) else { return empty(); };
let Some(timeline) = doc.descendants().find(|n| n.has_tag_name("TimelineObject")) else {
return ParsedPost {
tid,
create_time: 0,
author_username: fallback_author(),
content: String::new(),
media: Vec::new(),
location: String::new(),
};
return empty();
};
let create_time = xml_text(xml_child(timeline, "createTime"))