mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 05:55:15 +08:00
fix(daemon): 去重失败版本并优化状态输出
This commit is contained in:
@@ -1896,7 +1896,7 @@ fn print_human_json_value(value: &serde_json::Value) -> anyhow::Result<()> {
|
||||
print_json_field(value, "current_message", "当前消息");
|
||||
print_json_field(value, "download_progress", "下载进度");
|
||||
print_json_field(value, "version_state_path", "版本状态路径");
|
||||
print_json_field(value, "version_state", "版本状态");
|
||||
print_daemon_version_state_json_summary(value.get("version_state"));
|
||||
print_json_field(value, "resource_output_root", "资源目录");
|
||||
print_json_field(value, "state_dir", "状态目录");
|
||||
print_json_field(value, "socket_path", "socket");
|
||||
@@ -1935,6 +1935,49 @@ fn print_human_json_value(value: &serde_json::Value) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_daemon_version_state_json_summary(value: Option<&serde_json::Value>) {
|
||||
let Some(value) = value else {
|
||||
return;
|
||||
};
|
||||
if value.is_null() {
|
||||
return;
|
||||
}
|
||||
match serde_json::from_value::<OfficialVersionState>(value.clone()) {
|
||||
Ok(version_state) => print_daemon_version_state_summary(&version_state),
|
||||
Err(error) => print_field("版本状态", format!("无法解析:{error}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_daemon_version_state_summary(version_state: &OfficialVersionState) {
|
||||
print_optional_field(
|
||||
"当前完成版本",
|
||||
version_state
|
||||
.current_completed_version
|
||||
.as_ref()
|
||||
.map(|version| version.id.as_str()),
|
||||
);
|
||||
print_optional_field(
|
||||
"正在拉取版本",
|
||||
version_state
|
||||
.in_progress_version
|
||||
.as_ref()
|
||||
.map(|version| version.id.as_str()),
|
||||
);
|
||||
print_optional_field(
|
||||
"上一个可用版本",
|
||||
version_state
|
||||
.previous_available_version
|
||||
.as_ref()
|
||||
.map(|version| version.id.as_str()),
|
||||
);
|
||||
print_field("失败版本数", version_state.failed_versions.len());
|
||||
if let Some(failed) = version_state.failed_versions.last() {
|
||||
print_field("最近失败版本", &failed.version.id);
|
||||
print_field("最近失败时间", failed.failed_unix_seconds);
|
||||
print_field("最近失败原因", &failed.error);
|
||||
}
|
||||
}
|
||||
|
||||
fn print_json_field(value: &serde_json::Value, key: &str, label: &str) {
|
||||
let Some(value) = value.get(key) else {
|
||||
return;
|
||||
@@ -2177,28 +2220,7 @@ impl HumanReport for DaemonStatusReport {
|
||||
print_field("下载进度", format_daemon_download_progress(progress));
|
||||
}
|
||||
if let Some(version_state) = self.version_state.as_ref() {
|
||||
print_optional_field(
|
||||
"当前完成版本",
|
||||
version_state
|
||||
.current_completed_version
|
||||
.as_ref()
|
||||
.map(|version| version.id.as_str()),
|
||||
);
|
||||
print_optional_field(
|
||||
"正在拉取版本",
|
||||
version_state
|
||||
.in_progress_version
|
||||
.as_ref()
|
||||
.map(|version| version.id.as_str()),
|
||||
);
|
||||
print_optional_field(
|
||||
"上一个可用版本",
|
||||
version_state
|
||||
.previous_available_version
|
||||
.as_ref()
|
||||
.map(|version| version.id.as_str()),
|
||||
);
|
||||
print_field("失败版本数", version_state.failed_versions.len());
|
||||
print_daemon_version_state_summary(version_state);
|
||||
}
|
||||
print_optional_path_field("资源目录", self.resource_output_root.as_ref());
|
||||
print_optional_path_field("版本状态", self.version_state_path.as_ref());
|
||||
|
||||
Reference in New Issue
Block a user