@@ -71,7 +71,7 @@ impl UserApi {
71
71
// headers.insert("Sec-Fetch-Site", HeaderValue::from_static("same-origin"));
72
72
73
73
// let cookie = Self::get_csrf(username, password, headers.clone()).await?;
74
-
74
+
75
75
// let valid_data = Self::valid_check(headers.clone(), &cookie).await?;
76
76
77
77
// let cookie = if valid_data.0 {
@@ -95,7 +95,7 @@ impl UserApi {
95
95
96
96
// Ok(Self { client })
97
97
// }
98
-
98
+
99
99
// Soon will be added if i find way to overcome captcha
100
100
101
101
// async fn get_csrf(
@@ -190,26 +190,39 @@ impl UserApi {
190
190
. await ?;
191
191
192
192
let resp_info = serde_json:: from_str :: < CookieData > ( & cookie_info) ?;
193
-
193
+
194
194
// Soon will be added if i find way to overcome captcha
195
195
196
196
// let captcha_key = client.post(format!("https://www.recaptcha.net/recaptcha/enterprise/reload?k={}", resp_info.data.recaptchaKey)).headers(headers);
197
197
198
- if resp_info
199
- . data
200
- . userStatus
201
- . isSignedIn
202
- {
198
+ if resp_info. data . userStatus . isSignedIn {
203
199
return Ok ( ( true , String :: from ( token) ) ) ;
204
200
}
205
201
206
202
Ok ( ( false , String :: from ( token) ) )
207
203
}
208
204
209
- pub async fn set_problem ( & self , task : & str ) -> Result < Problem , Errors > {
205
+ pub async fn set_problem ( & self , problem_name : & str ) -> Result < Problem , Errors > {
206
+ let info = Self :: fetch_problem_full_data (
207
+ & self ,
208
+ Self :: get_question_name ( & self , String :: from ( problem_name) ) . await ?,
209
+ )
210
+ . await ?;
211
+
212
+ Ok ( Problem {
213
+ client : self . client . clone ( ) ,
214
+ task_search_name : info. 0 ,
215
+ full_data : info. 1 ,
216
+ } )
217
+ }
218
+
219
+ pub async fn set_problem_by_id (
220
+ & self ,
221
+ problem_id : u32 ,
222
+ ) -> Result < Problem , Errors > {
210
223
let info = Self :: fetch_problem_full_data (
211
224
& self ,
212
- Self :: get_question_name ( & self , String :: from ( task ) ) . await ?,
225
+ Self :: get_question_name ( & self , problem_id . to_string ( ) ) . await ?,
213
226
)
214
227
. await ?;
215
228
@@ -222,12 +235,12 @@ impl UserApi {
222
235
223
236
async fn fetch_problem_full_data (
224
237
& self ,
225
- task_name : String ,
238
+ problem : String ,
226
239
) -> Result < ( String , ProblemFullData ) , Errors > {
227
240
let json_obj = json ! ( {
228
241
"operationName" : "questionData" ,
229
242
"variables" : {
230
- "titleSlug" : task_name
243
+ "titleSlug" : problem
231
244
} ,
232
245
"query" : "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n canSeeQuestion\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n exampleTestcases\n categoryTitle\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n paidOnly\n hasVideoSolution\n paidOnlyVideo\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n enableDebugger\n envInfo\n libraryUrl\n adminUrl\n challengeQuestion {\n id\n date\n incompleteChallengeCount\n streakCount\n type\n __typename\n }\n __typename\n }\n }"
233
246
} ) ;
0 commit comments