Skip to content

Commit 5ee1d43

Browse files
committed
Fixes loading from database if a serialized ron DocSpan exists.
1 parent 25a87b5 commit 5ee1d43

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

edit-server/src/db/queries.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn get_single_page(db: &SqliteConnection, input_id: &str) -> Option<Doc<RtfS
6868
post.map_err::<Error, _>(|x| x.into())
6969
.map(|x| x.body.to_string())
7070
.and_then(|x| {
71+
eprintln!("loading... {:?}", x);
7172
Ok(oatie::deserialize::doc_ron(&x).or(serde_json::from_str::<Doc<RtfSchema>>(&x))?)
7273
})
7374
.ok()

oatie/src/deserialize.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -467,18 +467,23 @@ pub fn doc_ron(input: &str) -> Result<crate::doc::Doc<crate::rtf::RtfSchema>, Er
467467
match ron::de::from_str::<crate::doc::Doc<crate::rtf::RtfSchema>>(input) {
468468
Ok(value) => Ok(value),
469469
Err(err) => {
470+
// V3a Possibly a DocSpan not a Doc?
471+
if let Ok(value) = ron::de::from_str::<crate::doc::DocSpan<crate::rtf::RtfSchema>>(input) {
472+
return Ok(Doc(value));
473+
}
474+
470475
// Try V2 encoding.
471476
if let Ok(value) = v2::docspan_ron(&input) {
472-
Ok(Doc(value))
473-
} else {
474-
// Try V1 encoding.
475-
if let Ok(value) = v1::docspan_ron(&input) {
476-
Ok(Doc(value))
477-
} else {
478-
// Throw original ron error if error is encountered.
479-
Err(err.into())
480-
}
477+
return Ok(Doc(value));
478+
}
479+
480+
// Try V1 encoding.
481+
if let Ok(value) = v1::docspan_ron(&input) {
482+
return Ok(Doc(value));
481483
}
484+
485+
// Throw original ron error if error is encountered.
486+
Err(err.into())
482487
}
483488
}
484489
}
@@ -489,16 +494,16 @@ pub fn doc_json(input: &str) -> Result<crate::doc::Doc<crate::rtf::RtfSchema>, E
489494
Err(err) => {
490495
// Try V2 encoding.
491496
if let Ok(value) = v2::docspan_json(&input) {
492-
Ok(Doc(value))
493-
} else {
494-
// Try V1 encoding.
495-
if let Ok(value) = v1::docspan_json(&input) {
496-
Ok(Doc(value))
497-
} else {
498-
// Throw original ron error if error is encountered.
499-
Err(err.into())
500-
}
497+
return Ok(Doc(value));
498+
}
499+
500+
// Try V1 encoding.
501+
if let Ok(value) = v1::docspan_json(&input) {
502+
return Ok(Doc(value));
501503
}
504+
505+
// Throw original ron error if error is encountered.
506+
Err(err.into())
502507
}
503508
}
504509
}

0 commit comments

Comments
 (0)