@@ -7,7 +7,8 @@ use self::models::*;
7
7
use self :: schemas:: { problems:: dsl:: * , tags:: dsl:: * } ;
8
8
use self :: sql:: * ;
9
9
use crate :: helper:: test_cases_path;
10
- use crate :: { cfg, err:: Error , plugins:: LeetCode } ;
10
+ use crate :: Config ;
11
+ use crate :: { err:: Error , plugins:: LeetCode } ;
11
12
use colored:: Colorize ;
12
13
use diesel:: prelude:: * ;
13
14
use reqwest:: Response ;
@@ -40,12 +41,12 @@ pub struct Cache(pub LeetCode);
40
41
impl Cache {
41
42
/// Ref to sqlite connection
42
43
fn conn ( & self ) -> Result < SqliteConnection , Error > {
43
- Ok ( conn ( self . 0 . conf . storage . cache ( ) ?) )
44
+ Ok ( conn ( Config :: problems_filepath ( ) ?) )
44
45
}
45
46
46
47
/// Clean cache
47
48
pub fn clean ( & self ) -> Result < ( ) , Error > {
48
- Ok ( std:: fs:: remove_file ( & self . 0 . conf . storage . cache ( ) ?) ?)
49
+ Ok ( std:: fs:: remove_file ( Config :: problems_filepath ( ) ?) ?)
49
50
}
50
51
51
52
/// ref to download probems
@@ -55,7 +56,7 @@ impl Cache {
55
56
}
56
57
57
58
pub fn update_after_ac ( self , rid : i32 ) -> Result < ( ) , Error > {
58
- let c = conn ( self . 0 . conf . storage . cache ( ) ?) ;
59
+ let c = conn ( Config :: problems_filepath ( ) ?) ;
59
60
let target = problems. filter ( id. eq ( rid) ) ;
60
61
diesel:: update ( target) . set ( status. eq ( "ac" ) ) . execute ( & c) ?;
61
62
Ok ( ( ) )
@@ -307,32 +308,16 @@ impl Cache {
307
308
json. insert ( "data_input" , test_case) ;
308
309
309
310
let url = match run {
310
- Run :: Test => conf
311
- . sys
312
- . urls
313
- . get ( "test" )
314
- . ok_or ( Error :: NoneError ) ?
315
- . replace ( "$slug" , & p. slug ) ,
311
+ Run :: Test => conf. sys . urls . test . replace ( "$slug" , & p. slug ) ,
316
312
Run :: Submit => {
317
313
json. insert ( "judge_type" , "large" . to_string ( ) ) ;
318
- conf. sys
319
- . urls
320
- . get ( "submit" )
321
- . ok_or ( Error :: NoneError ) ?
322
- . replace ( "$slug" , & p. slug )
314
+ conf. sys . urls . submit . replace ( "$slug" , & p. slug )
323
315
}
324
316
} ;
325
317
326
318
Ok ( (
327
319
json,
328
- [
329
- url,
330
- conf. sys
331
- . urls
332
- . get ( "problems" )
333
- . ok_or ( Error :: NoneError ) ?
334
- . replace ( "$slug" , & p. slug ) ,
335
- ] ,
320
+ [ url, conf. sys . urls . problems . replace ( "$slug" , & p. slug ) ] ,
336
321
) )
337
322
}
338
323
@@ -395,8 +380,7 @@ impl Cache {
395
380
396
381
/// New cache
397
382
pub fn new ( ) -> Result < Self , Error > {
398
- let conf = cfg:: locate ( ) ?;
399
- let c = conn ( conf. storage . cache ( ) ?) ;
383
+ let c = conn ( Config :: problems_filepath ( ) ?) ;
400
384
diesel:: sql_query ( CREATE_PROBLEMS_IF_NOT_EXISTS ) . execute ( & c) ?;
401
385
diesel:: sql_query ( CREATE_TAGS_IF_NOT_EXISTS ) . execute ( & c) ?;
402
386
0 commit comments