@@ -10,6 +10,7 @@ pub enum Save {
1010 Storage ,
1111 Running ,
1212 V2ray ,
13+ Subscribes ,
1314}
1415fn create_storage_before ( ) {
1516 let home = env:: var ( "HOME" ) . unwrap ( ) ;
@@ -21,6 +22,7 @@ pub fn create_json_file(save: Save, input: String) -> Result<()> {
2122 Save :: Storage => format ! ( "{}/.config/tv2ray/storage.json" , home) ,
2223 Save :: Running => format ! ( "{}/.config/tv2ray/running.json" , home) ,
2324 Save :: V2ray => format ! ( "{}/.config/tv2ray/v2core.json" , home) ,
25+ Save :: Subscribes => format ! ( "{}/.config/tv2ray/subscribes.json" , home) ,
2426 } ;
2527 let path = Path :: new ( location. as_str ( ) ) ;
2628 let mut file = File :: create ( & path) ?;
@@ -34,6 +36,7 @@ fn get_json(save: Save) -> Result<String> {
3436 Save :: Storage => format ! ( "{}/.config/tv2ray/storage.json" , home) ,
3537 Save :: Running => format ! ( "{}/.config/tv2ray/running.json" , home) ,
3638 Save :: V2ray => format ! ( "{}/.config/tv2ray/v2core.json" , home) ,
39+ Save :: Subscribes => format ! ( "{}/.config/tv2ray/subscribes.json" , home) ,
3740 } ;
3841 let mut file = File :: open ( location) ?;
3942 let mut output = String :: new ( ) ;
@@ -54,6 +57,28 @@ pub fn start_v2core() -> String {
5457 let message_pre = v[ "v2core" ] . to_string ( ) ;
5558 crate :: spider:: remove_quotation ( message_pre)
5659}
60+ pub fn get_subs ( ) -> Vec < String > {
61+ create_storage_before ( ) ;
62+ let messages = match get_json ( Save :: Subscribes ) {
63+ Ok ( output) => output,
64+ Err ( _) => {
65+ create_json_file ( Save :: Storage , "[]" . to_string ( ) )
66+ . unwrap_or_else ( |err| panic ! ( "{}" , err) ) ;
67+ "[]" . to_string ( )
68+ }
69+ } ;
70+ let mut subscribes = Vec :: new ( ) ;
71+ let v: Value = serde_json:: from_str ( messages. as_str ( ) ) . unwrap ( ) ;
72+ let mut index = 0 ;
73+ while v[ index] != Value :: Null {
74+ let sub = v[ index] [ "url" ] . to_string ( ) ;
75+ let length = sub. len ( ) ;
76+ let sub = ( & sub[ 1 ..length - 1 ] ) . to_string ( ) ;
77+ subscribes. push ( sub) ;
78+ index += 1 ;
79+ }
80+ subscribes
81+ }
5782pub fn start ( ) -> Vec < Information > {
5883 create_storage_before ( ) ;
5984 let messages = match get_json ( Save :: Storage ) {
@@ -69,8 +94,8 @@ pub fn start() -> Vec<Information> {
6994 let mut index = 0 ;
7095 while v[ index] != Value :: Null {
7196 let the_url = v[ index] [ "url" ] . to_string ( ) ;
72- let lenghth = the_url. len ( ) ;
73- let instore = & the_url[ 1 ..lenghth - 1 ] ;
97+ let length = the_url. len ( ) ;
98+ let instore = & the_url[ 1 ..length - 1 ] ;
7499 informations. push ( Information {
75100 urls : instore. to_string ( ) ,
76101 func : v[ index] [ "func" ] . to_string ( ) ,
0 commit comments