Fix gallery availability check
This commit is contained in:
1 parent
715f863167
commit
0c7e3ac8b4
4 files changed
+19
-14
No files matched your search
@@ -125,11 +125,6 @@ private fun rethrowExactly(response: HttpResponse, body: Either<String, ByteBuff
|
||||
throw IpBannedException(message)
|
||||
}
|
||||
|
||||
// Check Gallery Not Available
|
||||
body.onLeft {
|
||||
if ("Gallery Not Available - " in it) throw e
|
||||
}
|
||||
|
||||
// Check parse error thrown by rust
|
||||
val cause = e.cause
|
||||
if (e is ParseException && cause is RuntimeException) {
|
||||
@@ -139,7 +134,12 @@ private fun rethrowExactly(response: HttpResponse, body: Either<String, ByteBuff
|
||||
"2" -> throw NotLoggedInException()
|
||||
"3" -> throw NoHathClientException()
|
||||
"4" -> throw InsufficientFundsException()
|
||||
is String if message.startsWith('5') -> throw IpBannedException(message.drop(1))
|
||||
is String if message.isNotEmpty() -> {
|
||||
when (message[0]) {
|
||||
'5' -> throw IpBannedException(message.substring(1))
|
||||
'6' -> throw EhException(message.substring(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ where
|
||||
{
|
||||
parse_raw_marshal_inplace(env, str, limit, |html| {
|
||||
let mut dom = tl::parse(html, options)?;
|
||||
ensure!(dom.version().is_some(), EhError::Error(html.to_string()));
|
||||
ensure!(dom.version().is_some(), EhError::IpBanned(html.to_string()));
|
||||
f(&mut dom, html)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ enum EhError {
|
||||
NeedLogin,
|
||||
NoHathClient,
|
||||
InsufficientFunds,
|
||||
IpBanned(String),
|
||||
Error(String),
|
||||
}
|
||||
|
||||
@@ -85,7 +86,8 @@ impl Display for EhError {
|
||||
EhError::NeedLogin => "2",
|
||||
EhError::NoHathClient => "3",
|
||||
EhError::InsufficientFunds => "4",
|
||||
EhError::Error(s) => &format!("5{s}"),
|
||||
EhError::IpBanned(s) => &format!("5{s}"),
|
||||
EhError::Error(s) => &format!("6{s}"),
|
||||
};
|
||||
f.write_str(msg)
|
||||
}
|
||||
|
||||
@@ -233,15 +233,11 @@ fn parse_detail(gd: &mut GalleryDetail, dom: &VDom, parser: &Parser, body: &str)
|
||||
|
||||
pub fn parse_gallery_detail(dom: &mut VDom, body: &str) -> Result<GalleryDetail> {
|
||||
let parser = dom.parser();
|
||||
let error = get_vdom_first_element_by_class_name(dom, "d");
|
||||
if let Some(tag) = error.and_then(|n| get_first_child(n.as_tag()?, parser)) {
|
||||
let node = tag.children().top()[0].get(parser).unwrap();
|
||||
bail!(EhError::Error(node.inner_text(parser).to_string()));
|
||||
}
|
||||
|
||||
let mut gallery_detail = GalleryDetail {
|
||||
tagGroups: parse_tag_groups(dom, parser, false)?,
|
||||
// Check availability in `parse_preview_list` as that will be called independently
|
||||
previewList: parse_preview_list(dom, parser)?,
|
||||
tagGroups: parse_tag_groups(dom, parser, false)?,
|
||||
comments: parse_comments(dom)?,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -474,6 +470,13 @@ pub fn parse_pages(dom: &VDom, parser: &Parser) -> Result<i32> {
|
||||
}
|
||||
|
||||
pub fn parse_preview_list(dom: &VDom, parser: &Parser) -> Result<Vec<GalleryPreview>> {
|
||||
// Check Gallery Not Available
|
||||
let error = get_vdom_first_element_by_class_name(dom, "d");
|
||||
if let Some(tag) = error.and_then(|n| get_first_child(n.as_tag()?, parser)) {
|
||||
let node = tag.children().top()[0].get(parser).unwrap();
|
||||
bail!(EhError::Error(node.inner_text(parser).to_string()));
|
||||
}
|
||||
|
||||
dom.get_element_by_id("gdt")
|
||||
.and_then(|n| n.get(parser)?.children())
|
||||
.context("Failed to find gdt")?
|
||||
|
||||
Reference in new issue
Block a user