Skip to content

Commit

Permalink
use ModIO lib instead of API
Browse files Browse the repository at this point in the history
  • Loading branch information
aNaOH committed Jun 12, 2024
1 parent e8f9f8e commit 2d67258
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use godot::prelude::*;
use godot::engine::Node;
use godot::builtin::meta::GodotConvert;

use modio::files::AddFileOptions;
use modio::mods::filters::Tags;
use modio::types::id::GameId;
use modio::{Credentials, Modio};
use modio::filter::prelude::*;
use modio::mods::Mod;
use modio::mods::{AddModOptions, Mod};

use std::fs::File;
use std::io::BufWriter;
Expand Down Expand Up @@ -194,13 +195,6 @@ impl ModIOClient {
let zip_path = modfile_path.to_owned() + ".zip";
Self::compress_to_zip(modfile_path, &zip_path).await?;

let modfile = read(&zip_path).await?;
let client = Client::new();

let mut form = multipart::Form::new()
.text("name", name.to_string())
.text("summary", summary.to_string())
.part("modfile", multipart::Part::bytes(modfile).file_name("mod.zip"));

let thumbnail = read(thumbnail_path).await?;
let img = image::open(thumbnail_path)?;
Expand All @@ -213,16 +207,9 @@ impl ModIOClient {
return Err("Thumbnail must be less than 8MB".into());
}

form = form.part("logo", multipart::Part::bytes(thumbnail).file_name("thumbnail.png"));

let response = client.post(format!("https://api.mod.io/v1/games/{}/mods", self.id))
.header("Authorization", format!("Bearer {}", api_key))
.multipart(form)
.send()
.await?;
let new_mod = self.client.with_credentials(Credentials::new(api_key)).game(GameId::new(self.id)).mods().add(AddModOptions::new(name, thumbnail_path, summary)).await?;

let response_text = response.text().await?;
println!("{}", response_text);
self.client.with_credentials(Credentials::new(api_key)).game(GameId::new(self.id)).mod_(new_mod.id).files().add(AddFileOptions::with_file(zip_path)).await?;

Ok(true)
}
Expand Down

0 comments on commit 2d67258

Please sign in to comment.