mirror of
https://github.com/MedzikUser/imgurs
synced 2024-08-15 00:03:19 +00:00
chore: change String
to &str
This commit is contained in:
parent
6f9559c6d8
commit
f4e0044678
8 changed files with 42 additions and 33 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.7.3] - 2022-05-18
|
||||||
|
### Library
|
||||||
|
- add code comments and tests
|
||||||
|
- change `String` to `&str` in ImgurClient functions
|
||||||
|
|
||||||
|
### Other
|
||||||
|
- bump deps
|
||||||
|
- use `anyhow::Result<...>` instead `Result<..., Error>`
|
||||||
|
|
||||||
## [0.7.2] - 2022-04-05
|
## [0.7.2] - 2022-04-05
|
||||||
### HotFix
|
### HotFix
|
||||||
- fix upload image from file
|
- fix upload image from file
|
||||||
|
@ -106,7 +115,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
- upload image
|
- upload image
|
||||||
|
|
||||||
<!-- next-url -->
|
<!-- next-url -->
|
||||||
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.7.2...HEAD
|
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.7.3...HEAD
|
||||||
|
[0.7.3]: https://github.com/MedzikUser/imgurs/commits/v0.7.3
|
||||||
[0.7.2]: https://github.com/MedzikUser/imgurs/commits/v0.7.2
|
[0.7.2]: https://github.com/MedzikUser/imgurs/commits/v0.7.2
|
||||||
[0.7.1]: https://github.com/MedzikUser/imgurs/commits/v0.7.1
|
[0.7.1]: https://github.com/MedzikUser/imgurs/commits/v0.7.1
|
||||||
[0.7.0]: https://github.com/MedzikUser/imgurs/commits/v0.7.0
|
[0.7.0]: https://github.com/MedzikUser/imgurs/commits/v0.7.0
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
||||||
))]
|
))]
|
||||||
// use xclip (or a similar program that is installed) because the kernel deletes the clipboard after the process ends
|
// use xclip (or a similar program that is installed) because the kernel deletes the clipboard after the process ends
|
||||||
pub fn set_clipboard(content: String) {
|
pub fn set_clipboard(content: &str) {
|
||||||
fn is_program_in_path(program: &str) -> bool {
|
fn is_program_in_path(program: &str) -> bool {
|
||||||
if let Ok(path) = std::env::var("PATH") {
|
if let Ok(path) = std::env::var("PATH") {
|
||||||
for p in path.split(':') {
|
for p in path.split(':') {
|
||||||
|
@ -79,7 +79,7 @@ pub fn set_clipboard(content: String) {
|
||||||
unix,
|
unix,
|
||||||
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
||||||
)))]
|
)))]
|
||||||
pub fn set_clipboard(content: String) {
|
pub fn set_clipboard(content: &str) {
|
||||||
let mut clipboard = arboard::Clipboard::new().unwrap();
|
let mut clipboard = arboard::Clipboard::new().unwrap();
|
||||||
clipboard.set_text(content).unwrap();
|
clipboard.set_text(content).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
use chrono::{prelude::DateTime, Utc};
|
use chrono::{prelude::DateTime, Utc};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use imgurs::ImgurClient;
|
use imgurs::ImgurClient;
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
|
||||||
|
|
||||||
pub async fn credits(client: ImgurClient) {
|
pub async fn credits(client: ImgurClient) {
|
||||||
// get client ratelimit from imgur api
|
// get client ratelimit from imgur api
|
||||||
|
|
|
@ -10,5 +10,5 @@ pub async fn image_info(client: ImgurClient, id: String) {
|
||||||
.expect("send request to imfur api");
|
.expect("send request to imfur api");
|
||||||
|
|
||||||
// print image information from imgur
|
// print image information from imgur
|
||||||
print_image_info(info);
|
print_image_info(&info);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use imgurs::ImageInfo;
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
// print image information from imgur
|
// print image information from imgur
|
||||||
pub fn print_image_info(i: ImageInfo) {
|
pub fn print_image_info(i: &ImageInfo) {
|
||||||
// format image upload date
|
// format image upload date
|
||||||
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
|
let d = UNIX_EPOCH + Duration::from_secs(i.data.datetime.try_into().unwrap());
|
||||||
let datetime = DateTime::<Utc>::from(d);
|
let datetime = DateTime::<Utc>::from(d);
|
||||||
|
@ -23,37 +23,34 @@ pub fn print_image_info(i: ImageInfo) {
|
||||||
|
|
||||||
// image title
|
// image title
|
||||||
if i.data.title != None {
|
if i.data.title != None {
|
||||||
|
let title = i.data.title.clone();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
"title".green(),
|
"title".green(),
|
||||||
i.data
|
title.unwrap_or_else(|| "unknown".to_string()).magenta()
|
||||||
.title
|
|
||||||
.unwrap_or_else(|| "unknown".to_string())
|
|
||||||
.magenta()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// image description
|
// image description
|
||||||
if i.data.description != None {
|
if i.data.description != None {
|
||||||
|
let desc = i.data.description.clone();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
"description".green(),
|
"description".green(),
|
||||||
i.data
|
desc.unwrap_or_else(|| "unknown".to_string()).magenta()
|
||||||
.description
|
|
||||||
.unwrap_or_else(|| "unknown".to_string())
|
|
||||||
.magenta()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// image deletehas
|
// image deletehas
|
||||||
if i.data.deletehash != None {
|
if i.data.deletehash != None {
|
||||||
|
let delhash = i.data.deletehash.clone();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
"deletehash".green(),
|
"deletehash".green(),
|
||||||
i.data
|
delhash.unwrap_or_else(|| "unknown".to_string()).magenta()
|
||||||
.deletehash
|
|
||||||
.unwrap_or_else(|| "unknown".to_string())
|
|
||||||
.magenta()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use super::clipboard::set_clipboard;
|
|
||||||
use imgurs::ImgurClient;
|
use imgurs::ImgurClient;
|
||||||
use notify_rust::Notification;
|
use notify_rust::Notification;
|
||||||
|
|
||||||
use crate::{cli::webhook::send_discord_webhook, config::toml};
|
use crate::{
|
||||||
|
cli::{clipboard::set_clipboard, print_image_info, webhook::send_discord_webhook},
|
||||||
use super::print_image_info;
|
config::toml,
|
||||||
|
};
|
||||||
|
|
||||||
// show notification
|
// show notification
|
||||||
macro_rules! notify (
|
macro_rules! notify (
|
||||||
|
@ -23,7 +23,7 @@ pub async fn upload_image(client: ImgurClient, path: String) {
|
||||||
let mut i = client.upload_image(&path).await.unwrap_or_else(|err| {
|
let mut i = client.upload_image(&path).await.unwrap_or_else(|err| {
|
||||||
notify!(Notification::new()
|
notify!(Notification::new()
|
||||||
.summary("Error!")
|
.summary("Error!")
|
||||||
.body(&format!("Error: {}", &err.to_string()))
|
.body(&format!("Error: {}", err))
|
||||||
.appname("Imgurs")); // I don't think you can set it to error
|
.appname("Imgurs")); // I don't think you can set it to error
|
||||||
|
|
||||||
panic!("send request to imagur api: {}", err)
|
panic!("send request to imagur api: {}", err)
|
||||||
|
@ -35,7 +35,7 @@ pub async fn upload_image(client: ImgurClient, path: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// print image information from imgur
|
// print image information from imgur
|
||||||
print_image_info(i.clone());
|
print_image_info(&i);
|
||||||
|
|
||||||
// send notification that the image has been uploaded
|
// send notification that the image has been uploaded
|
||||||
notify!(Notification::new()
|
notify!(Notification::new()
|
||||||
|
@ -44,12 +44,12 @@ pub async fn upload_image(client: ImgurClient, path: String) {
|
||||||
|
|
||||||
// if enabled copy link to clipboard
|
// if enabled copy link to clipboard
|
||||||
if config.clipboard.enabled {
|
if config.clipboard.enabled {
|
||||||
set_clipboard(i.data.link.clone())
|
set_clipboard(&i.data.link)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if enabled send embed with link and deletehash to discord (something like logger)
|
// if enabled send embed with link and deletehash to discord (something like logger)
|
||||||
if config.discord_webhook.enabled {
|
if config.discord_webhook.enabled {
|
||||||
send_discord_webhook(i.data.link, i.data.deletehash.unwrap())
|
send_discord_webhook(&i.data.link, &i.data.deletehash.unwrap())
|
||||||
.await
|
.await
|
||||||
.expect("send discord webhook");
|
.expect("send discord webhook");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ use crate::config::toml;
|
||||||
|
|
||||||
// send embed with link and deletehash to discord (something like logger)
|
// send embed with link and deletehash to discord (something like logger)
|
||||||
pub async fn send_discord_webhook(
|
pub async fn send_discord_webhook(
|
||||||
link: String,
|
link: &str,
|
||||||
deletehash: String,
|
deletehash: &str,
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
// get discord webhook uri from config
|
// get discord webhook uri from config
|
||||||
let url = toml::parse().discord_webhook.uri;
|
let url = toml::parse().discord_webhook.uri;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
use serde::Serialize;
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
pub mod toml;
|
pub mod toml;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub imgur: ConfigImgur,
|
pub imgur: ConfigImgur,
|
||||||
pub notification: ConfigNotification,
|
pub notification: ConfigNotification,
|
||||||
|
@ -10,23 +11,23 @@ pub struct Config {
|
||||||
pub discord_webhook: ConfigDiscordWebhook,
|
pub discord_webhook: ConfigDiscordWebhook,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ConfigImgur {
|
pub struct ConfigImgur {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub image_cdn: String,
|
pub image_cdn: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ConfigNotification {
|
pub struct ConfigNotification {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ConfigClipboard {
|
pub struct ConfigClipboard {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ConfigDiscordWebhook {
|
pub struct ConfigDiscordWebhook {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub uri: String,
|
pub uri: String,
|
||||||
|
|
Loading…
Reference in a new issue