1
1
use std:: error:: Error ;
2
2
3
+ use problem_actions:: Problem ;
4
+ use problem_build:: { Filters , TaskBuilder } ;
3
5
use reqwest:: header:: { HeaderMap , HeaderValue } ;
4
6
use serde_json:: { json, Value } ;
5
- use source:: { cookie:: CookieData , descr:: TaskData , taskfulldata:: TaskFullData } ;
6
- use task_actions:: Task ;
7
- use task_build:: { Filters , TaskBuilder } ;
7
+ use resources:: { cookie:: CookieData , descr:: ProblemData , problemfulldata:: ProblemFullData } ;
8
8
9
- pub mod source ;
10
- pub mod task_actions ;
11
- pub mod task_build ;
9
+ pub mod problem_actions ;
10
+ pub mod problem_build ;
11
+ pub mod resources ;
12
12
13
13
pub struct UserApi {
14
14
client : reqwest:: Client ,
@@ -70,76 +70,11 @@ impl UserApi {
70
70
71
71
let query = r#"
72
72
query globalData {
73
- feature {
74
- questionTranslation
75
- subscription
76
- signUp
77
- discuss
78
- mockInterview
79
- contest
80
- store
81
- chinaProblemDiscuss
82
- socialProviders
83
- studentFooter
84
- enableChannels
85
- dangerZone
86
- enableSharedWorker
87
- enableRecaptchaV3
88
- enableDebugger
89
- enableDebuggerPremium
90
- enableAutocomplete
91
- enableAutocompletePremium
92
- enableAllQuestionsRaw
93
- autocompleteLanguages
94
- enableIndiaPricing
95
- enableReferralDiscount
96
- maxTimeTravelTicketCount
97
- enableStoreShippingForm
98
- enableCodingChallengeV2
99
- __typename
100
- }
101
- streakCounter {
102
- streakCount
103
- daysSkipped
104
- currentDayCompleted
105
- __typename
106
- }
107
- currentTimestamp
108
73
userStatus {
109
74
isSignedIn
110
- isAdmin
111
- isStaff
112
- isSuperuser
113
- isMockUser
114
- isTranslator
115
- isPremium
116
- isVerified
117
- checkedInToday
118
- username
119
- realName
120
- avatar
121
- optedIn
122
- requestRegion
123
- region
124
- activeSessionId
125
- permissions
126
- notificationStatus {
127
- lastModified
128
- numUnread
129
- __typename
130
- }
131
- completedFeatureGuides
132
- __typename
133
75
}
134
- siteRegion
135
- chinaHost
136
- websocketUrl
137
- recaptchaKey
138
- recaptchaKeyV2
139
- sitewideAnnouncement
140
- userCountryCode
141
76
}
142
- "# ;
77
+ "# ;
143
78
144
79
let json_data = json ! ( {
145
80
"operationName" : operation_name,
@@ -161,10 +96,7 @@ impl UserApi {
161
96
. text ( )
162
97
. await
163
98
{
164
- Ok ( data) => {
165
- // println!("{}", data);
166
- data
167
- } ,
99
+ Ok ( data) => data,
168
100
Err ( _err) => return Err ( "Can't take cookie info" . into ( ) ) ,
169
101
} ;
170
102
@@ -173,31 +105,30 @@ impl UserApi {
173
105
. userStatus
174
106
. isSignedIn
175
107
{
176
- println ! ( "work" ) ;
177
108
return Ok ( ( true , String :: from ( token) ) ) ;
178
109
}
179
110
180
111
Ok ( ( false , String :: from ( token) ) )
181
112
}
182
113
183
- pub async fn set_task ( & self , task : & str ) -> Result < Task , Box < dyn Error > > {
184
- let info = Self :: get_full_data (
114
+ pub async fn set_problm ( & self , task : & str ) -> Result < Problem , Box < dyn Error > > {
115
+ let info = Self :: fetch_full_data (
185
116
& self ,
186
117
Self :: get_question_name ( & self , String :: from ( task) ) . await ?,
187
118
)
188
119
. await ?;
189
120
190
- Ok ( Task {
121
+ Ok ( Problem {
191
122
client : self . client . clone ( ) ,
192
123
task_search_name : info. 0 ,
193
124
full_data : info. 1 ,
194
125
} )
195
126
}
196
127
197
- async fn get_full_data (
128
+ async fn fetch_full_data (
198
129
& self ,
199
130
task_name : String ,
200
- ) -> Result < ( String , TaskFullData ) , Box < dyn Error > > {
131
+ ) -> Result < ( String , ProblemFullData ) , Box < dyn Error > > {
201
132
let json_obj = json ! ( {
202
133
"operationName" : "questionData" ,
203
134
"variables" : {
@@ -215,7 +146,7 @@ impl UserApi {
215
146
. send ( )
216
147
. await
217
148
. unwrap ( )
218
- . json :: < TaskFullData > ( )
149
+ . json :: < ProblemFullData > ( )
219
150
. await
220
151
{
221
152
Ok ( data) => data,
@@ -225,11 +156,11 @@ impl UserApi {
225
156
Ok ( ( full_data. data . question . titleSlug . clone ( ) , full_data) )
226
157
}
227
158
228
- pub async fn show_tasks_list (
159
+ pub async fn show_problm_list (
229
160
& self ,
230
161
key_word : & str ,
231
162
limit : u32 ,
232
- ) -> Result < TaskData , Box < dyn Error > > {
163
+ ) -> Result < ProblemData , Box < dyn Error > > {
233
164
let query = json ! ( {
234
165
"query" : "query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) { problemsetQuestionList: questionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters ) { total: totalNum questions: data { acRate difficulty freqBar frontendQuestionId: questionFrontendId isFavor paidOnly: isPaidOnly status title titleSlug topicTags { name id slug } hasSolution hasVideoSolution } } }" ,
235
166
"variables" : {
@@ -259,10 +190,10 @@ impl UserApi {
259
190
return Err ( "Problem does not found" . into ( ) ) ;
260
191
}
261
192
262
- Ok ( serde_json:: from_str :: < TaskData > ( & task_info. unwrap ( ) ) ?)
193
+ Ok ( serde_json:: from_str :: < ProblemData > ( & task_info. unwrap ( ) ) ?)
263
194
}
264
195
265
- pub fn show_task_builder ( & self ) -> TaskBuilder {
196
+ pub fn problem_builder ( & self ) -> TaskBuilder {
266
197
TaskBuilder {
267
198
client : self . client . clone ( ) ,
268
199
key_word : String :: new ( ) ,
@@ -274,7 +205,7 @@ impl UserApi {
274
205
275
206
async fn get_question_name ( & self , name : String ) -> Result < String , Box < dyn Error > > {
276
207
let query = json ! ( {
277
- "query" : "query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) { problemsetQuestionList: questionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters ) { total: totalNum questions: data { acRate difficulty freqBar frontendQuestionId: questionFrontendId isFavor paidOnly: isPaidOnly status title titleSlug topicTags { name id slug } hasSolution hasVideoSolution } } }" ,
208
+ "query" : "query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) { problemsetQuestionList: questionList( categorySlug: $categorySlug limit: $limit skip: $skip filters: $filters ) { questions: data { titleSlug } } }" ,
278
209
"variables" : {
279
210
"categorySlug" : "" ,
280
211
"skip" : 0 ,
@@ -302,14 +233,15 @@ impl UserApi {
302
233
return Err ( "Task does not found" . into ( ) ) ;
303
234
}
304
235
305
- let parsed_data: TaskData = serde_json:: from_str ( & task_info. unwrap ( ) ) ?;
236
+ let parsed_data: ProblemData = serde_json:: from_str ( & task_info. unwrap ( ) ) ?;
306
237
307
238
Ok ( parsed_data. data . problemsetQuestionList . questions [ 0 ]
308
239
. titleSlug
309
240
. clone ( ) )
310
241
}
311
242
}
312
243
244
+ #[ derive( Debug ) ]
313
245
#[ allow( unused) ]
314
246
pub enum Category {
315
247
AllTopics ,
@@ -320,13 +252,15 @@ pub enum Category {
320
252
Concurrency ,
321
253
}
322
254
255
+ #[ derive( Debug ) ]
323
256
#[ allow( unused) ]
324
257
pub enum Difficulty {
325
258
Easy ,
326
259
Medium ,
327
260
Hard ,
328
261
}
329
262
263
+ #[ derive( Debug ) ]
330
264
#[ allow( unused) ]
331
265
pub enum Status {
332
266
Todo ,
0 commit comments