-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
143 changed files
with
1,539 additions
and
1,311 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
pub const BLOG_BACKEND: &str = "https://i.cnblogs.com/api"; | ||
#[macro_export] | ||
macro_rules! blog_backend { | ||
($($arg:tt)*) => {{ | ||
use $crate::cnb::api_base::BLOG_BACKEND; | ||
use alloc::format; | ||
let rest = format!($($arg)*); | ||
format!("{}{}", BLOG_BACKEND, rest) | ||
}}; | ||
} | ||
|
||
pub const OPENAPI: &str = "https://api.cnblogs.com/api"; | ||
#[macro_export] | ||
macro_rules! openapi { | ||
($($arg:tt)*) => {{ | ||
use $crate::cnb::api_base::OPENAPI; | ||
use alloc::format; | ||
let rest = format!($($arg)*); | ||
format!("{}{}", OPENAPI, rest) | ||
}}; | ||
} | ||
|
||
pub const OAUTH: &str = "https://oauth.cnblogs.com"; | ||
#[macro_export] | ||
macro_rules! oauth { | ||
($($arg:tt)*) => {{ | ||
use $crate::cnb::api_base::OAUTH; | ||
use alloc::format; | ||
let rest = format!($($arg)*); | ||
format!("{}{}", OAUTH, rest) | ||
}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
use crate::cnb::ing::{IngReq, ING_API_BASE_URL}; | ||
use crate::cnb::ing::IngReq; | ||
use crate::http::body_or_err; | ||
use crate::infra::http::setup_auth; | ||
use crate::infra::result::{homo_result_string, HomoResult, IntoResult}; | ||
use crate::panic_hook; | ||
use crate::infra::result::{HomoResult, ResultExt}; | ||
use crate::{openapi, panic_hook}; | ||
use alloc::format; | ||
use alloc::string::String; | ||
use anyhow::{anyhow, Result}; | ||
use anyhow::Result; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(js_class = IngReq)] | ||
impl IngReq { | ||
#[wasm_bindgen(js_name = getComment)] | ||
pub async fn export_get_comment(&self, ing_id: usize) -> HomoResult<String> { | ||
panic_hook!(); | ||
let url = format!("{ING_API_BASE_URL}/{ing_id}/comments"); | ||
let url = openapi!("/statuses/{}/comments", ing_id); | ||
|
||
let client = reqwest::Client::new().get(url); | ||
|
||
let req = setup_auth(client, &self.token, self.is_pat_token); | ||
|
||
let result: Result<String> = try { | ||
let resp = req.send().await?; | ||
let code = resp.status(); | ||
|
||
if code.is_success() { | ||
resp.text().await? | ||
} else { | ||
let text = resp.text().await?; | ||
anyhow!("{}: {}", code, text).into_err()? | ||
} | ||
body_or_err(resp).await? | ||
}; | ||
|
||
homo_result_string(result) | ||
result.homo_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
pub mod api_base; | ||
pub mod ing; | ||
pub mod oauth; | ||
pub mod post; | ||
pub mod post_category; | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::cnb::post::PostReq; | ||
use crate::http::unit_or_err; | ||
use crate::infra::http::setup_auth; | ||
use crate::infra::result::ResultExt; | ||
use crate::{blog_backend, panic_hook}; | ||
use alloc::format; | ||
use alloc::string::String; | ||
use anyhow::Result; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(js_class = PostReq)] | ||
impl PostReq { | ||
#[wasm_bindgen(js_name = delOne)] | ||
pub async fn export_del_one(&self, post_id: usize) -> Result<(), String> { | ||
panic_hook!(); | ||
let url = blog_backend!("/posts/{}", post_id); | ||
|
||
let client = reqwest::Client::new().delete(url); | ||
|
||
let req = setup_auth(client, &self.token, self.is_pat_token); | ||
|
||
let result: Result<()> = try { | ||
let resp = req.send().await?; | ||
unit_or_err(resp).await? | ||
}; | ||
|
||
result.err_to_string() | ||
} | ||
} |
Oops, something went wrong.