diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 8af78d7..5e1309f 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -177,7 +177,16 @@ impl Cache { .json() .await?; debug!("{:#?}", &json); - parser::desc(&mut rdesc, json).ok_or(Error::NoneError)?; + match parser::desc(&mut rdesc, json) { + None => return Err(Error::NoneError), + Some(false) => return + if self.is_session_bad().await { + Err(Error::CookieError) + } else { + Err(Error::PremiumError) + }, + Some(true) => () + } // update the question let sdesc = serde_json::to_string(&rdesc)?; diff --git a/src/cache/parser.rs b/src/cache/parser.rs index 130fbee..fb9ad2b 100644 --- a/src/cache/parser.rs +++ b/src/cache/parser.rs @@ -29,7 +29,11 @@ pub fn problem(problems: &mut Vec, v: Value) -> Option<()> { } /// desc parser -pub fn desc(q: &mut Question, v: Value) -> Option<()> { +pub fn desc(q: &mut Question, v: Value) -> Option { + /* None - parsing failed + * Some(false) - content was null (premium?) + * Some(true) - content was parsed + */ let o = &v .as_object()? .get("data")? @@ -37,6 +41,10 @@ pub fn desc(q: &mut Question, v: Value) -> Option<()> { .get("question")? .as_object()?; + if *o.get("content")? == Value::Null { + return Some(false); + } + *q = Question { content: o.get("content")?.as_str().unwrap_or("").to_string(), stats: serde_json::from_str(o.get("stats")?.as_str()?).ok()?, @@ -55,7 +63,7 @@ pub fn desc(q: &mut Question, v: Value) -> Option<()> { .to_string(), }; - Some(()) + Some(true) } /// tag parser diff --git a/src/err.rs b/src/err.rs index 8fd9b57..3ae8cc1 100644 --- a/src/err.rs +++ b/src/err.rs @@ -14,6 +14,7 @@ pub enum Error { FeatureError(String), ScriptError(String), CookieError, + PremiumError, DecryptError, SilentError, NoneError, @@ -37,6 +38,13 @@ impl std::fmt::Debug for Error { .yellow() .bold(), ), + Error::PremiumError => write!( + f, + "{} \ + Your leetcode account lacks a premium subscription, which the given problem requires.\n \ + If this looks like a mistake, please open a new issue at: {}", + e, + "https://github.com/clearloop/leetcode-cli/".underline()), Error::DownloadError(s) => write!(f, "{} Download {} failed, please try again", e, s), Error::NetworkError(s) => write!(f, "{} {}, please try again", e, s), Error::ParseError(s) => write!(f, "{} {}", e, s), diff --git a/src/helper.rs b/src/helper.rs index 5d8d746..b68fe68 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -147,7 +147,11 @@ mod html { impl HTML for String { fn ser(&self) -> Vec { // empty tags - let tks = self.to_string(); + let tks = { + let mut s = self.clone(); + // some problems (e.g. 1653) have ZWSPs. + s.retain(|x| x != '\u{200B}'); + s }; let res: Vec; // styled {