Skip to content

Commit 33d7836

Browse files
authored
fix: img extract (#178)
1 parent 5a3c0e9 commit 33d7836

File tree

143 files changed

+1539
-1311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+1539
-1311
lines changed

package.json

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

rs/src/base64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::infra::result::{homo_result_string, HomoResult, IntoResult};
1+
use crate::infra::result::{HomoResult, IntoResult, ResultExt};
22
use crate::panic_hook;
33
use alloc::string::String;
44
use anyhow::Result;
@@ -20,7 +20,7 @@ impl RsBase64 {
2020
panic_hook!();
2121
let text = decode(base64);
2222

23-
homo_result_string(text)
23+
text.homo_string()
2424
}
2525

2626
#[wasm_bindgen(js_name = encodeUrl)]
@@ -33,7 +33,7 @@ impl RsBase64 {
3333
panic_hook!();
3434
let text = decode_url(base64url);
3535

36-
homo_result_string(text)
36+
text.homo_string()
3737
}
3838
}
3939

rs/src/cnb/api_base.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pub const BLOG_BACKEND: &str = "https://i.cnblogs.com/api";
2+
#[macro_export]
3+
macro_rules! blog_backend {
4+
($($arg:tt)*) => {{
5+
use $crate::cnb::api_base::BLOG_BACKEND;
6+
use alloc::format;
7+
let rest = format!($($arg)*);
8+
format!("{}{}", BLOG_BACKEND, rest)
9+
}};
10+
}
11+
12+
pub const OPENAPI: &str = "https://api.cnblogs.com/api";
13+
#[macro_export]
14+
macro_rules! openapi {
15+
($($arg:tt)*) => {{
16+
use $crate::cnb::api_base::OPENAPI;
17+
use alloc::format;
18+
let rest = format!($($arg)*);
19+
format!("{}{}", OPENAPI, rest)
20+
}};
21+
}
22+
23+
pub const OAUTH: &str = "https://oauth.cnblogs.com";
24+
#[macro_export]
25+
macro_rules! oauth {
26+
($($arg:tt)*) => {{
27+
use $crate::cnb::api_base::OAUTH;
28+
use alloc::format;
29+
let rest = format!($($arg)*);
30+
format!("{}{}", OAUTH, rest)
31+
}};
32+
}

rs/src/cnb/ing/comment.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::cnb::ing::{IngReq, ING_API_BASE_URL};
1+
use crate::cnb::ing::IngReq;
2+
use crate::http::unit_or_err;
23
use crate::infra::http::{setup_auth, APPLICATION_JSON};
3-
use crate::infra::result::IntoResult;
4-
use crate::panic_hook;
4+
use crate::infra::result::ResultExt;
5+
use crate::{openapi, panic_hook};
56
use alloc::format;
6-
use alloc::string::{String, ToString};
7-
use anyhow::{anyhow, Result};
8-
use core::ops::Not;
7+
use alloc::string::String;
8+
use anyhow::Result;
99
use reqwest::header::CONTENT_TYPE;
1010
use serde::{Deserialize, Serialize};
1111
use wasm_bindgen::prelude::*;
@@ -32,7 +32,7 @@ impl IngReq {
3232
parent_comment_id: Option<usize>,
3333
) -> Result<(), String> {
3434
panic_hook!();
35-
let url = format!("{ING_API_BASE_URL}/{ing_id}/comments");
35+
let url = openapi!("/statuses/{}/comments", ing_id);
3636

3737
let client = reqwest::Client::new().post(url);
3838

@@ -47,16 +47,10 @@ impl IngReq {
4747
let result: Result<()> = try {
4848
let body = serde_json::to_string_pretty(&body)?;
4949
let req = req.body(body);
50-
5150
let resp = req.send().await?;
52-
let code = resp.status();
53-
54-
if code.is_success().not() {
55-
let text = resp.text().await?;
56-
anyhow!("{}: {}", code, text).into_err()?
57-
}
51+
unit_or_err(resp).await?
5852
};
5953

60-
result.map_err(|e| e.to_string())
54+
result.err_to_string()
6155
}
6256
}

rs/src/cnb/ing/get_comment.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
1-
use crate::cnb::ing::{IngReq, ING_API_BASE_URL};
1+
use crate::cnb::ing::IngReq;
2+
use crate::http::body_or_err;
23
use crate::infra::http::setup_auth;
3-
use crate::infra::result::{homo_result_string, HomoResult, IntoResult};
4-
use crate::panic_hook;
4+
use crate::infra::result::{HomoResult, ResultExt};
5+
use crate::{openapi, panic_hook};
56
use alloc::format;
67
use alloc::string::String;
7-
use anyhow::{anyhow, Result};
8+
use anyhow::Result;
89
use wasm_bindgen::prelude::*;
910

1011
#[wasm_bindgen(js_class = IngReq)]
1112
impl IngReq {
1213
#[wasm_bindgen(js_name = getComment)]
1314
pub async fn export_get_comment(&self, ing_id: usize) -> HomoResult<String> {
1415
panic_hook!();
15-
let url = format!("{ING_API_BASE_URL}/{ing_id}/comments");
16+
let url = openapi!("/statuses/{}/comments", ing_id);
1617

1718
let client = reqwest::Client::new().get(url);
1819

1920
let req = setup_auth(client, &self.token, self.is_pat_token);
2021

2122
let result: Result<String> = try {
2223
let resp = req.send().await?;
23-
let code = resp.status();
24-
25-
if code.is_success() {
26-
resp.text().await?
27-
} else {
28-
let text = resp.text().await?;
29-
anyhow!("{}: {}", code, text).into_err()?
30-
}
24+
body_or_err(resp).await?
3125
};
3226

33-
homo_result_string(result)
27+
result.homo_string()
3428
}
3529
}

rs/src/cnb/ing/get_list.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::cnb::ing::{IngReq, ING_API_BASE_URL};
1+
use crate::cnb::ing::IngReq;
2+
use crate::http::body_or_err;
23
use crate::infra::http::setup_auth;
3-
use crate::infra::result::{homo_result_string, HomoResult, IntoResult};
4-
use crate::panic_hook;
4+
use crate::infra::result::{HomoResult, ResultExt};
5+
use crate::{openapi, panic_hook};
56
use alloc::string::String;
67
use alloc::{format, vec};
7-
use anyhow::{anyhow, Result};
8+
use anyhow::Result;
89
use wasm_bindgen::prelude::*;
910

1011
#[wasm_bindgen(js_class = IngReq)]
@@ -17,7 +18,7 @@ impl IngReq {
1718
ing_type: usize,
1819
) -> HomoResult<String> {
1920
panic_hook!();
20-
let url = format!("{ING_API_BASE_URL}/@{ing_type}");
21+
let url = openapi!("/statuses/@{}", ing_type);
2122

2223
let client = reqwest::Client::new().get(url);
2324

@@ -26,16 +27,9 @@ impl IngReq {
2627

2728
let result: Result<String> = try {
2829
let resp = req.send().await?;
29-
let code = resp.status();
30-
31-
if code.is_success() {
32-
resp.text().await?
33-
} else {
34-
let text = resp.text().await?;
35-
anyhow!("{}: {}", code, text).into_err()?
36-
}
30+
body_or_err(resp).await?
3731
};
3832

39-
homo_result_string(result)
33+
result.homo_string()
4034
}
4135
}

rs/src/cnb/ing/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use crate::panic_hook;
77
use alloc::string::{String, ToString};
88
use wasm_bindgen::prelude::*;
99

10-
const ING_API_BASE_URL: &str = "https://api.cnblogs.com/api/statuses";
11-
1210
#[wasm_bindgen(js_name = IngReq)]
1311
pub struct IngReq {
1412
token: String,

rs/src/cnb/ing/pub.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::cnb::ing::{IngReq, ING_API_BASE_URL};
1+
use crate::cnb::ing::IngReq;
2+
use crate::http::unit_or_err;
23
use crate::infra::http::{setup_auth, APPLICATION_JSON};
3-
use crate::infra::result::IntoResult;
4-
use crate::panic_hook;
4+
use crate::infra::result::ResultExt;
5+
use crate::{openapi, panic_hook};
56
use alloc::string::{String, ToString};
6-
use anyhow::{anyhow, Result};
7-
use core::ops::Not;
7+
use anyhow::Result;
88
use reqwest::header::CONTENT_TYPE;
99
use serde_json::json;
1010
use wasm_bindgen::prelude::*;
@@ -14,7 +14,7 @@ impl IngReq {
1414
#[wasm_bindgen(js_name = pub)]
1515
pub async fn export_pub(&self, content: &str, is_private: bool) -> Result<(), String> {
1616
panic_hook!();
17-
let url = ING_API_BASE_URL;
17+
let url = openapi!("/statuses");
1818

1919
let body = json!({
2020
"content": content,
@@ -30,14 +30,9 @@ impl IngReq {
3030

3131
let result: Result<()> = try {
3232
let resp = req.send().await?;
33-
let code = resp.status();
34-
35-
if code.is_success().not() {
36-
let text = resp.text().await?;
37-
anyhow!("{}: {}", code, text).into_err()?
38-
}
33+
unit_or_err(resp).await?
3934
};
4035

41-
result.map_err(|e| e.to_string())
36+
result.err_to_string()
4237
}
4338
}

rs/src/cnb/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
pub mod api_base;
12
pub mod ing;
23
pub mod oauth;
4+
pub mod post;
5+
pub mod post_category;
36
pub mod user;

rs/src/cnb/oauth/get_token.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::cnb::oauth::OauthReq;
2-
use crate::cnb::oauth::OAUTH_API_BASE_URL;
2+
use crate::http::body_or_err;
33
use crate::infra::http::{cons_query_string, APPLICATION_X3WFU};
4-
use crate::infra::result::{homo_result_string, HomoResult, IntoResult};
5-
use crate::panic_hook;
4+
use crate::infra::result::{HomoResult, ResultExt};
5+
use crate::{oauth, panic_hook};
66
use alloc::string::String;
77
use alloc::{format, vec};
8-
use anyhow::{anyhow, Result};
8+
use anyhow::Result;
99
use reqwest::header::CONTENT_TYPE;
1010
use wasm_bindgen::prelude::*;
1111

@@ -19,7 +19,7 @@ impl OauthReq {
1919
callback_url: &str,
2020
) -> HomoResult<String> {
2121
panic_hook!();
22-
let url = format!("{OAUTH_API_BASE_URL}/connect/token");
22+
let url = oauth!("/connect/token");
2323

2424
let client = reqwest::Client::new().post(url);
2525

@@ -38,16 +38,9 @@ impl OauthReq {
3838

3939
let result: Result<String> = try {
4040
let resp = req.send().await?;
41-
let code = resp.status();
42-
43-
if code.is_success() {
44-
resp.text().await?
45-
} else {
46-
let text = resp.text().await?;
47-
anyhow!("{}: {}", code, text).into_err()?
48-
}
41+
body_or_err(resp).await?
4942
};
5043

51-
homo_result_string(result)
44+
result.homo_string()
5245
}
5346
}

0 commit comments

Comments
 (0)