@@ -56,106 +56,6 @@ impl UserApi {
56
56
Ok ( Self { client} )
57
57
}
58
58
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
-
159
59
async fn valid_check ( mut headers : HeaderMap , cookie : & str ) ->Result < ( bool , String ) , Errors > {
160
60
let token =if let Some ( token) = cookie
161
61
. strip_prefix ( "csrftoken=" )
@@ -191,10 +91,6 @@ impl UserApi {
191
91
192
92
let resp_info = serde_json:: from_str :: < CookieData > ( & cookie_info) ?;
193
93
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
-
198
94
if resp_info. data . userStatus . isSignedIn {
199
95
return Ok ( ( true , String :: from ( token) ) ) ;
200
96
}
@@ -216,10 +112,7 @@ impl UserApi {
216
112
} )
217
113
}
218
114
219
- pub async fn set_problem_by_id (
220
- & self ,
221
- problem_id : u32 ,
222
- ) ->Result < Problem , Errors > {
115
+ pub async fn set_problem_by_id ( & self , problem_id : u32 ) ->Result < Problem , Errors > {
223
116
let info =Self :: fetch_problem_full_data (
224
117
& self ,
225
118
Self :: get_question_name ( & self , problem_id. to_string ( ) ) . await ?,