Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Jun 12, 2024
1 parent 1ba489e commit 759a057
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub enum Index {
/// Set the URL for the index (pass default to reset)
Url {
/// URL to set
url: String,
#[clap(long, short)]
url: Option<String>,
},

/// Secrets...
Expand Down Expand Up @@ -246,6 +247,10 @@ fn create_entry(out_path: &Path) {
}

fn submit(action: MyModAction, config: &mut Config) {
if action != MyModAction::Create || action != MyModAction::Update {
fatal!("Invalid action");
}

if config.index_token.is_none() {
fatal!("You are not logged in");
}
Expand Down Expand Up @@ -450,7 +455,13 @@ pub fn subcommand(config: &mut Config, cmd: Index) {
}
Index::Login => index_auth::login(config),
Index::Invalidate => index_auth::invalidate(config),
Index::Url { url } => set_index_url(url, config),
Index::Url { url } => {
if let Some(u) = url {
set_index_url(u, config);
} else {
info!("Your current index URL is: {}", config.index_url);
}
}
Index::Mods { action } => match action {
MyModAction::Create => submit(action, config),
MyModAction::Update => submit(action, config),
Expand Down
24 changes: 20 additions & 4 deletions src/index_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ fn update_dev_status(config: &Config) {
return;
}
let developer = developer.unwrap();

info!("Developer found: ");
println!("{}", developer);

let mut verified = developer.verified;
loop {
let status = ask_value("New status (verified/unverified)", None, true);
Expand All @@ -350,15 +354,27 @@ fn update_dev_status(config: &Config) {

let client = reqwest::blocking::Client::new();

let url = index::get_index_url(format!("/v1/developers/{}", username).to_string(), config);
let url = index::get_index_url(
format!("/v1/developers/{}", developer.id).to_string(),
config,
);
let response = client
.post(url)
.put(url)
.bearer_auth(config.index_token.as_ref().unwrap())
.json(&json!({ "verified": verified }))
.send()
.nice_unwrap("Failed to update developer");

if response.status() != 204 {
fail!("Failed to upadte developer");
if response.status() != 200 {
let json = response.json::<serde_json::Value>();
if let Ok(j) = json {
if j.is_object() && j.as_object().unwrap().contains_key("error") {
let err = j.as_object().unwrap().get("error").unwrap().to_string();
fatal!("Failed to update developer: {}", err);
}
} else {
fatal!("Failed to update developer. No error received from index.");
}
}

info!("Developer updated successfully");
Expand Down

0 comments on commit 759a057

Please sign in to comment.