@@ -11,7 +11,7 @@ use crate::repo::Module;
11
11
12
12
use clap:: { Parser , Subcommand } ;
13
13
use repo:: Repo ;
14
- use std:: io:: { Read , Write } ;
14
+ use std:: io:: Write ;
15
15
use std:: {
16
16
fs:: { self , File } ,
17
17
path:: Path ,
@@ -101,8 +101,10 @@ struct Args {
101
101
commands : Commands ,
102
102
}
103
103
104
+ const REPOS_SOURCE : & str = "/data/adb/mmrl/repos.json" ;
105
+
104
106
fn setup ( ) {
105
- let file_path = Path :: new ( "/data/adb/mmrl/repos.list" ) ; // Replace with the desired file path
107
+ let file_path = Path :: new ( REPOS_SOURCE ) ; // Replace with the desired file path
106
108
107
109
if !file_path. exists ( ) {
108
110
// Create all directories in the path if they don't exist
@@ -125,33 +127,44 @@ fn setup() {
125
127
} ;
126
128
127
129
// You can write to the file if needed
128
- if let Err ( err) = writeln ! ( file, "https://raw.githubusercontent.com/ya0211/magisk-modules-alt-repo/main/json/modules.json; " ) {
130
+ if let Err ( err) = writeln ! ( file, "[ \n \t \" https://raw.githubusercontent.com/ya0211/magisk-modules-alt-repo/main/json/modules.json\" \n ] " ) {
129
131
eprintln ! ( "Error writing to file: {}" , err) ;
130
132
}
131
133
}
132
134
}
133
135
136
+ async fn fetch_repos ( url : String ) -> Result < Repo , reqwest:: Error > {
137
+ let response = reqwest:: get ( url) . await ?;
138
+ let body = response. json ( ) . await ?;
139
+ Ok ( body)
140
+ }
141
+
134
142
#[ tokio:: main]
135
143
async fn main ( ) {
136
144
setup ( ) ;
137
- let client = reqwest:: Client :: new ( ) ;
145
+ let client = reqwest:: Client :: builder ( ) . build ( ) . unwrap ( ) ;
138
146
let args = Args :: parse ( ) ;
139
147
let mut modules: Vec < Module > = vec ! [ ] ;
140
- let mut file = File :: open ( "example.txt" ) . unwrap ( ) ;
141
- let mut contents = String :: new ( ) ;
142
- file. read_to_string ( & mut contents) . unwrap ( ) ;
143
- println ! ( "Available repos:" ) ;
144
- for repo in contents. split ( ";" ) {
145
- let response = client. get ( repo) . send ( ) . await . unwrap ( ) ;
146
- let mut json: Repo = response. json ( ) . await . unwrap ( ) ;
147
- println ! ( "{}" , json. name) ;
148
- modules. append ( & mut json. modules ) ;
148
+
149
+ let file = File :: open ( REPOS_SOURCE ) . expect ( "file should open read only" ) ;
150
+ let contents: Vec < String > = serde_json:: from_reader ( file) . unwrap ( ) ;
151
+
152
+ let mut tasks = vec ! [ ] ;
153
+
154
+ for url in contents {
155
+ let task = tokio:: spawn ( fetch_repos ( url) ) ;
156
+ tasks. push ( task) ;
157
+ }
158
+
159
+ for task in tasks {
160
+ let result = task. await . unwrap ( ) ;
161
+ modules. append ( & mut result. unwrap ( ) . modules ) ;
149
162
}
150
163
151
164
match args. commands {
152
165
Commands :: Info { ids } => {
153
166
for id in ids {
154
- info ( & modules, id) . await ;
167
+ info ( & modules. clone ( ) , id) . await ;
155
168
}
156
169
exit ( 0 ) ;
157
170
}
0 commit comments