Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit 496c332

Browse files
committed
throw PremiumError when locked questions are queried for details
1 parent ff7baf0 commit 496c332

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

‎src/cache/mod.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,16 @@ impl Cache {
177177
.json()
178178
.await?;
179179
debug!("{:#?}", &json);
180-
parser::desc(&mut rdesc, json).ok_or(Error::NoneError)?;
180+
match parser::desc(&mut rdesc, json) {
181+
None => return Err(Error::NoneError),
182+
Some(false) => return
183+
if self.is_session_bad().await {
184+
Err(Error::CookieError)
185+
} else {
186+
Err(Error::PremiumError)
187+
},
188+
Some(true) => ()
189+
}
181190

182191
// update the question
183192
let sdesc = serde_json::to_string(&rdesc)?;

‎src/cache/parser.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@ pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Option<()> {
2929
}
3030

3131
/// desc parser
32-
pub fn desc(q: &mut Question, v: Value) -> Option<()> {
32+
pub fn desc(q: &mut Question, v: Value) -> Option<bool> {
33+
/* None - parsing failed
34+
* Some(false) - content was null (premium?)
35+
* Some(true) - content was parsed
36+
*/
3337
let o = &v
3438
.as_object()?
3539
.get("data")?
3640
.as_object()?
3741
.get("question")?
3842
.as_object()?;
3943

44+
if *o.get("content")? == Value::Null {
45+
return Some(false);
46+
}
47+
4048
*q = Question {
4149
content: o.get("content")?.as_str().unwrap_or("").to_string(),
4250
stats: serde_json::from_str(o.get("stats")?.as_str()?).ok()?,
@@ -55,7 +63,7 @@ pub fn desc(q: &mut Question, v: Value) -> Option<()> {
5563
.to_string(),
5664
};
5765

58-
Some(())
66+
Some(true)
5967
}
6068

6169
/// tag parser

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /