Movatterモバイル変換


[0]ホーム

URL:


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

Commite23009e

Browse files
committed
feat: Added a little bit code optimization
1 parent5c8eae8 commite23009e

File tree

3 files changed

+4
-111
lines changed

3 files changed

+4
-111
lines changed

‎Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name ="leetcoderustapi"
3-
version ="1.0.7"
3+
version ="1.0.8"
44
authors = ["1101-1","https://github.com/1101-1/"]
55
edition ="2021"
66
license ="MIT"
@@ -24,4 +24,4 @@ reqwest = { version = "0.11.18", features = ["json", "multipart"] }
2424
serde = {version ="1.0.164",features = ["derive"] }
2525
serde_json ="1.0.99"
2626
thiserror ="1.0.41"
27-
tokio = {version ="1.29.1",features = ["time","full"] }
27+
tokio = {version ="1.29.1",features = ["time"] }

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This Rust library provides a convenient way to interact with the LeetCode API, a
1111
Add the following line to your`Cargo.toml` file:
1212
```toml
1313
[dependencies]
14-
leetcoderustapi ="1.0.6"
14+
leetcoderustapi ="1.0.8"
1515
```
1616
##Usage
1717
###Authentication

‎src/lib.rs

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -56,106 +56,6 @@ impl UserApi {
5656
Ok(Self{ client})
5757
}
5858

59-
// Soon will be added if i find way to overcome captcha
60-
61-
// pub async fn new_with_login(username: &str, password: &str) -> Result<Self, Errors> {
62-
// let mut headers = HeaderMap::new();
63-
64-
// headers.insert("Host", HeaderValue::from_static("leetcode.com"));
65-
// headers.insert("User-Agent", HeaderValue::from_static("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"));
66-
// headers.insert("Origin", HeaderValue::from_static("https://leetcode.com"));
67-
// headers.insert("Referer", HeaderValue::from_static("https://leetcode.com/"));
68-
// headers.insert("Connection", HeaderValue::from_static("keep-alive"));
69-
// headers.insert("Sec-Fetch-Dest", HeaderValue::from_static("empty"));
70-
// headers.insert("Sec-Fetch-Mode", HeaderValue::from_static("cors"));
71-
// headers.insert("Sec-Fetch-Site", HeaderValue::from_static("same-origin"));
72-
73-
// let cookie = Self::get_csrf(username, password, headers.clone()).await?;
74-
75-
// let valid_data = Self::valid_check(headers.clone(), &cookie).await?;
76-
77-
// let cookie = if valid_data.0 {
78-
// cookie
79-
// } else {
80-
// return Err(error::Errors::ApiError(
81-
// "Err to login into account".into(),
82-
// ));
83-
// };
84-
85-
// let token = valid_data.1;
86-
87-
// headers.insert("Cookie", HeaderValue::from_str(&cookie).unwrap());
88-
// headers.insert("x-csrftoken", HeaderValue::from_str(&token).unwrap());
89-
90-
// headers.insert("content-type", HeaderValue::from_static("application/json"));
91-
92-
// let client = reqwest::Client::builder()
93-
// .default_headers(headers)
94-
// .build()?;
95-
96-
// Ok(Self { client })
97-
// }
98-
99-
// Soon will be added if i find way to overcome captcha
100-
101-
// async fn get_csrf(
102-
// username: &str,
103-
// password: &str,
104-
// mut headers: HeaderMap,
105-
// ) -> Result<String, Errors> {
106-
// let client = reqwest::Client::new();
107-
108-
// let cookie = client
109-
// .get("https://leetcode.com/")
110-
// .send()
111-
// .await?
112-
// .headers()
113-
// .get("set-cookie")
114-
// .unwrap()
115-
// .to_str()
116-
// .unwrap()
117-
// .to_owned();
118-
119-
// let token = Self::valid_check(headers.clone(), &cookie).await?.1;
120-
121-
// let boundary = format!(
122-
// "---------------------------{}",
123-
// uuid::Uuid::new_v4().simple()
124-
// );
125-
126-
// headers.insert(
127-
// "content-type",
128-
// HeaderValue::from_str(&format!("multipart/form-data; boundary=-----------------------------117813464726863521931465700267")).unwrap(),
129-
// );
130-
131-
// headers.insert("Cookie", HeaderValue::from_str(&cookie).unwrap());
132-
// headers.insert("x-csrftoken", HeaderValue::from_str(&token).unwrap());
133-
134-
// let form_data = vec![
135-
// ("csrfmiddlewaretoken", token),
136-
// ("login", username.into()),
137-
// ("password", password.into()),
138-
// ("next", "/".into()),
139-
// ];
140-
141-
// let mut multipart = Form::new();
142-
// for (key, value) in form_data.iter() {
143-
// let part = Part::text(value.to_string()).file_name(key.to_string());
144-
// multipart = multipart.part(key.to_string(), part);
145-
// }
146-
147-
// let x = client
148-
// .post("https://leetcode.com/accounts/login/")
149-
// .headers(headers)
150-
// .multipart(multipart)
151-
// .send()
152-
// .await.unwrap().text().await.unwrap();
153-
154-
// println!("{:?}", x);
155-
156-
// Ok(x)
157-
// }
158-
15959
asyncfnvalid_check(mutheaders:HeaderMap,cookie:&str) ->Result<(bool,String),Errors>{
16060
let token =ifletSome(token) = cookie
16161
.strip_prefix("csrftoken=")
@@ -191,10 +91,6 @@ impl UserApi {
19191

19292
let resp_info = serde_json::from_str::<CookieData>(&cookie_info)?;
19393

194-
// Soon will be added if i find way to overcome captcha
195-
196-
// let captcha_key = client.post(format!("https://www.recaptcha.net/recaptcha/enterprise/reload?k={}", resp_info.data.recaptchaKey)).headers(headers);
197-
19894
if resp_info.data.userStatus.isSignedIn{
19995
returnOk((true,String::from(token)));
20096
}
@@ -216,10 +112,7 @@ impl UserApi {
216112
})
217113
}
218114

219-
pubasyncfnset_problem_by_id(
220-
&self,
221-
problem_id:u32,
222-
) ->Result<Problem,Errors>{
115+
pubasyncfnset_problem_by_id(&self,problem_id:u32) ->Result<Problem,Errors>{
223116
let info =Self::fetch_problem_full_data(
224117
&self,
225118
Self::get_question_name(&self, problem_id.to_string()).await?,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp