Skip to content

Commit abc7dd6

Browse files
committed
Add mutiple repos
1 parent 5edc4f6 commit abc7dd6

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ serde_ini = "0.2.0"
2323
regex = "1.10.2"
2424
async-recursion = "1.0.5"
2525
openssl = { version = "0.10.45", features = ["vendored"] }
26+
url = "2.2"
2627

2728
[dependencies.confy]
2829
features = ["toml_conf"]

src/main.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::repo::Module;
1111

1212
use clap::{Parser, Subcommand};
1313
use repo::Repo;
14-
use std::io::{Read, Write};
14+
use std::io::Write;
1515
use std::{
1616
fs::{self, File},
1717
path::Path,
@@ -101,8 +101,10 @@ struct Args {
101101
commands: Commands,
102102
}
103103

104+
const REPOS_SOURCE: &str = "/data/adb/mmrl/repos.json";
105+
104106
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
106108

107109
if !file_path.exists() {
108110
// Create all directories in the path if they don't exist
@@ -125,33 +127,44 @@ fn setup() {
125127
};
126128

127129
// 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]") {
129131
eprintln!("Error writing to file: {}", err);
130132
}
131133
}
132134
}
133135

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+
134142
#[tokio::main]
135143
async fn main() {
136144
setup();
137-
let client = reqwest::Client::new();
145+
let client = reqwest::Client::builder().build().unwrap();
138146
let args = Args::parse();
139147
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);
149162
}
150163

151164
match args.commands {
152165
Commands::Info { ids } => {
153166
for id in ids {
154-
info(&modules, id).await;
167+
info(&modules.clone(), id).await;
155168
}
156169
exit(0);
157170
}

src/repo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Version {
5757
pub(crate) fn find_module(modules: &Vec<Module>, id: String) -> Module {
5858
let module_exists = modules.iter().any(|m| m.id == id);
5959
if !module_exists {
60-
println!("Unable to find {}", id);
60+
eprintln!("Unable to find {}", id);
6161
exit(1);
6262
}
6363
let module_pos = modules.iter().position(|m| m.id == id).unwrap();

src/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use futures_util::StreamExt;
22
use indicatif::{ProgressBar, ProgressStyle};
33
use regex::Regex;
4-
use reqwest::{Client, Url};
4+
use reqwest::Client;
5+
use url::Url;
56
use std::cmp::min;
67
use std::fs::File;
78
use std::io;

0 commit comments

Comments
 (0)