mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 05:34:55 +08:00
fix(sync): 规范 release flow 状态码解析
This commit is contained in:
@@ -2519,7 +2519,7 @@ fn build_resource_state_report(state_dir: &Path) -> anyhow::Result<serde_json::V
|
||||
let flow_status_code = status_file
|
||||
.as_ref()
|
||||
.and_then(|status| status.status_code.as_deref())
|
||||
.and_then(ReleaseFlowStatusCode::from_str)
|
||||
.and_then(|code| code.parse::<ReleaseFlowStatusCode>().ok())
|
||||
.or_else(|| {
|
||||
if version_state
|
||||
.as_ref()
|
||||
|
||||
@@ -147,7 +147,7 @@ impl ReleaseFlowStatusCode {
|
||||
}
|
||||
|
||||
/// Parses a status code read from a persisted daemon/RPC snapshot.
|
||||
pub fn from_str(code: &str) -> Option<Self> {
|
||||
fn parse_wire_code(code: &str) -> Option<Self> {
|
||||
Some(match code {
|
||||
"official.unavailable" => Self::OfficialUnavailable,
|
||||
"official.checking" => Self::OfficialChecking,
|
||||
@@ -255,6 +255,14 @@ impl ReleaseFlowStatusCode {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for ReleaseFlowStatusCode {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(code: &str) -> Result<Self, Self::Err> {
|
||||
Self::parse_wire_code(code).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ReleaseFlowStatusCode;
|
||||
@@ -292,4 +300,11 @@ mod tests {
|
||||
assert_eq!(labels.len(), unique.len());
|
||||
assert!(labels.iter().all(|label| label.contains('.')));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_codes_round_trip_through_from_str() {
|
||||
let code = ReleaseFlowStatusCode::LocalizedPublished;
|
||||
assert_eq!(code.as_str().parse::<ReleaseFlowStatusCode>(), Ok(code));
|
||||
assert!("unknown.status".parse::<ReleaseFlowStatusCode>().is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user