fedi avatar support
This commit is contained in:
parent
3688567e96
commit
42894c4939
|
@ -437,6 +437,16 @@ version = "0.3.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime_guess"
|
||||||
|
version = "2.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
|
||||||
|
dependencies = [
|
||||||
|
"mime",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
@ -667,6 +677,7 @@ dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"mime",
|
"mime",
|
||||||
|
"mime_guess",
|
||||||
"native-tls",
|
"native-tls",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
|
@ -1009,6 +1020,15 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicase"
|
||||||
|
version = "2.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
|
||||||
|
dependencies = [
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.13"
|
version = "0.3.13"
|
||||||
|
@ -1047,6 +1067,12 @@ version = "0.2.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "want"
|
name = "want"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|
|
@ -9,7 +9,7 @@ edition = "2021"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
serde = { version = "1.0.192", features = ["derive"] }
|
serde = { version = "1.0.192", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
reqwest = { version = "0.11.22", features = ["json"] }
|
reqwest = { version = "0.11.22", features = ["json", "multipart"] }
|
||||||
rofi = "0.3.0"
|
rofi = "0.3.0"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
|
||||||
|
|
|
@ -11,5 +11,10 @@
|
||||||
"token": "// Discord user token",
|
"token": "// Discord user token",
|
||||||
"python_path": "// Path to the python executable",
|
"python_path": "// Path to the python executable",
|
||||||
"script_path": "// Path to updatepfp.py"
|
"script_path": "// Path to updatepfp.py"
|
||||||
|
},
|
||||||
|
"pleroma_module": {
|
||||||
|
"enabled": true,
|
||||||
|
"instance" : "// Pleroma instance url",
|
||||||
|
"token": "// Pleroma bearer token"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use reqwest::header::{USER_AGENT, AUTHORIZATION};
|
use reqwest::header::{USER_AGENT, AUTHORIZATION};
|
||||||
|
use reqwest::multipart::{Part, Form};
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
@ -16,7 +17,8 @@ struct Config {
|
||||||
pk_key: String,
|
pk_key: String,
|
||||||
sp_key: String,
|
sp_key: String,
|
||||||
pfp_module: PfpModule,
|
pfp_module: PfpModule,
|
||||||
disc_module: DiscModule
|
disc_module: DiscModule,
|
||||||
|
pleroma_module: PleromaModule,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
@ -34,6 +36,13 @@ struct DiscModule {
|
||||||
script_path: String,
|
script_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct PleromaModule {
|
||||||
|
enabled: bool,
|
||||||
|
instance: String,
|
||||||
|
token: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
struct System {
|
struct System {
|
||||||
pk_userid: String,
|
pk_userid: String,
|
||||||
|
@ -77,6 +86,11 @@ const EXAMPLE_JSON: &str = r#"{
|
||||||
"token": "// Discord user token",
|
"token": "// Discord user token",
|
||||||
"python_path": "// Path to the python executable",
|
"python_path": "// Path to the python executable",
|
||||||
"script_path": "// Path to updatepfp.py"
|
"script_path": "// Path to updatepfp.py"
|
||||||
|
},
|
||||||
|
"pleroma_module": {
|
||||||
|
"enabled": true,
|
||||||
|
"instance" : "// Pleroma instance url",
|
||||||
|
"token": "// Pleroma bearer token"
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
|
@ -316,6 +330,10 @@ fn get(config_path: String) -> Result<(), &'static str> {
|
||||||
let mut c = Command::new("sh").arg("-c").arg(format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path)).spawn().expect("Discord module error");
|
let mut c = Command::new("sh").arg("-c").arg(format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path)).spawn().expect("Discord module error");
|
||||||
let _ = c.wait().expect("Error");
|
let _ = c.wait().expect("Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.pleroma_module.enabled {
|
||||||
|
let _ = http_patch_request_pleroma(config.pleroma_module.instance + "/api/v1/accounts/update_credentials", format!("Bearer {}", &config.pleroma_module.token).as_str(), config.pfp_module.pfp_output_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,3 +638,17 @@ async fn http_patch_request(url: String, key: &str, body: String ) -> Result<(),
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn http_patch_request_pleroma(url: String, key: &str, file_path: String ) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let form = Form::new().part("avatar", Part::bytes(fs::read(file_path).unwrap()).file_name("face.png").mime_str("image/png").unwrap());
|
||||||
|
let c = client
|
||||||
|
.patch(url)
|
||||||
|
.multipart(form)
|
||||||
|
.header(USER_AGENT, "Pluralsync")
|
||||||
|
.header(AUTHORIZATION, key);
|
||||||
|
let _res = c.send()
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue