mirror of https://github.com/MedzikUser/imgurs
rustfmt
This commit is contained in:
parent
bfb10f5274
commit
4145e7e86b
|
@ -1,5 +1,5 @@
|
||||||
use std::fmt;
|
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
macro_rules! api_url (
|
macro_rules! api_url (
|
||||||
($path: expr) => (
|
($path: expr) => (
|
||||||
|
@ -25,7 +25,7 @@ impl ImgurHandle {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
ImgurHandle {
|
ImgurHandle {
|
||||||
client_id: client_id,
|
client_id: client_id,
|
||||||
client: client
|
client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@ pub async fn delete_image(c: ImgurHandle, delete_hash: String) -> Result<String,
|
||||||
|
|
||||||
if status.is_client_error() || status.is_server_error() {
|
if status.is_client_error() || status.is_server_error() {
|
||||||
let body = res.text().await.map_err(|err| err.to_string())?;
|
let body = res.text().await.map_err(|err| err.to_string())?;
|
||||||
Err(format!("server returned non-successful status code = {status}. body = {body}"))
|
Err(format!(
|
||||||
|
"server returned non-successful status code = {status}. body = {body}"
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok("If the delete hash was correct the image was deleted!".to_string())
|
Ok("If the delete hash was correct the image was deleted!".to_string())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod rate_limit;
|
|
||||||
pub mod configuration;
|
pub mod configuration;
|
||||||
pub mod upload_image;
|
|
||||||
pub mod delete_image;
|
pub mod delete_image;
|
||||||
|
pub mod rate_limit;
|
||||||
|
pub mod upload_image;
|
||||||
|
|
|
@ -40,7 +40,9 @@ pub async fn rate_limit(c: ImgurHandle) -> Result<RateLimitInfo, String> {
|
||||||
|
|
||||||
if status.is_client_error() || status.is_server_error() {
|
if status.is_client_error() || status.is_server_error() {
|
||||||
let body = res.text().await.map_err(|err| err.to_string())?;
|
let body = res.text().await.map_err(|err| err.to_string())?;
|
||||||
Err(format!("server returned non-successful status code = {status}. body = {body}"))
|
Err(format!(
|
||||||
|
"server returned non-successful status code = {status}. body = {body}"
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
let content: RateLimitInfo = res.json().await.map_err(|err| err.to_string())?;
|
let content: RateLimitInfo = res.json().await.map_err(|err| err.to_string())?;
|
||||||
Ok(content)
|
Ok(content)
|
||||||
|
|
|
@ -51,7 +51,9 @@ pub async fn upload_image(c: ImgurHandle, image: &str) -> Result<ImageInfo, Stri
|
||||||
|
|
||||||
if status.is_client_error() || status.is_server_error() {
|
if status.is_client_error() || status.is_server_error() {
|
||||||
let body = res.text().await.map_err(|err| err.to_string())?;
|
let body = res.text().await.map_err(|err| err.to_string())?;
|
||||||
Err(format!("server returned non-successful status code = {status}. body = {body}"))
|
Err(format!(
|
||||||
|
"server returned non-successful status code = {status}. body = {body}"
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
let content: ImageInfo = res.json().await.map_err(|err| err.to_string())?;
|
let content: ImageInfo = res.json().await.map_err(|err| err.to_string())?;
|
||||||
Ok(content)
|
Ok(content)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clap::{Parser, Subcommand, AppSettings};
|
use clap::{AppSettings, Parser, Subcommand};
|
||||||
|
|
||||||
use imgurs::api::configuration::ImgurHandle;
|
use imgurs::api::configuration::ImgurHandle;
|
||||||
|
|
||||||
|
@ -26,17 +26,13 @@ enum Commands {
|
||||||
setting(AppSettings::ArgRequiredElseHelp),
|
setting(AppSettings::ArgRequiredElseHelp),
|
||||||
about = "Upload image to imgur"
|
about = "Upload image to imgur"
|
||||||
)]
|
)]
|
||||||
Upload {
|
Upload { path: String },
|
||||||
path: String
|
|
||||||
},
|
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
setting(AppSettings::ArgRequiredElseHelp),
|
setting(AppSettings::ArgRequiredElseHelp),
|
||||||
about = "Upload image to imgur"
|
about = "Upload image to imgur"
|
||||||
)]
|
)]
|
||||||
Delete {
|
Delete { delete_hash: String },
|
||||||
delete_hash: String
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn parse(client: ImgurHandle) {
|
pub async fn parse(client: ImgurHandle) {
|
||||||
|
@ -44,18 +40,15 @@ pub async fn parse(client: ImgurHandle) {
|
||||||
|
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Commands::Credits => {
|
Commands::Credits => {
|
||||||
credits::credits(client)
|
credits::credits(client).await;
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Upload { path } => {
|
Commands::Upload { path } => {
|
||||||
upload_image::upload_image(client, path)
|
upload_image::upload_image(client, path).await;
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Delete { delete_hash } => {
|
Commands::Delete { delete_hash } => {
|
||||||
delete_image::delete_image(client, delete_hash.to_string())
|
delete_image::delete_image(client, delete_hash.to_string()).await;
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use imgurs::api::configuration::ImgurHandle;
|
use imgurs::api::configuration::ImgurHandle;
|
||||||
use imgurs::api::rate_limit::*;
|
use imgurs::api::rate_limit::*;
|
||||||
|
|
||||||
use log::{info, error};
|
use log::{error, info};
|
||||||
|
|
||||||
use chrono::prelude::DateTime;
|
use chrono::prelude::DateTime;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use std::time::{UNIX_EPOCH, Duration};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
pub async fn credits(client: ImgurHandle) {
|
pub async fn credits(client: ImgurHandle) {
|
||||||
match rate_limit(client).await {
|
match rate_limit(client).await {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use imgurs::api::configuration::ImgurHandle;
|
|
||||||
use imgurs::api;
|
use imgurs::api;
|
||||||
|
use imgurs::api::configuration::ImgurHandle;
|
||||||
|
|
||||||
use log::{info, error};
|
use log::{error, info};
|
||||||
|
|
||||||
pub async fn delete_image(client: ImgurHandle, delete_hash: String) {
|
pub async fn delete_image(client: ImgurHandle, delete_hash: String) {
|
||||||
match api::delete_image::delete_image(client, delete_hash).await {
|
match api::delete_image::delete_image(client, delete_hash).await {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod credits;
|
pub mod credits;
|
||||||
pub mod upload_image;
|
|
||||||
pub mod delete_image;
|
pub mod delete_image;
|
||||||
|
pub mod upload_image;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use imgurs::api::configuration::ImgurHandle;
|
use imgurs::api::configuration::ImgurHandle;
|
||||||
|
|
||||||
use log::{info, error};
|
|
||||||
use std::path::Path;
|
|
||||||
use std::fs;
|
|
||||||
use base64;
|
use base64;
|
||||||
|
use log::{error, info};
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use chrono::prelude::DateTime;
|
use chrono::prelude::DateTime;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use std::time::{UNIX_EPOCH, Duration};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
pub async fn upload_image(client: ImgurHandle, path: &str) {
|
pub async fn upload_image(client: ImgurHandle, path: &str) {
|
||||||
let image: String;
|
let image: String;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
use toml::from_str;
|
|
||||||
use serde_derive::Deserialize;
|
|
||||||
use dirs::config_dir;
|
use dirs::config_dir;
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
|
use toml::from_str;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub imgur: ConfigImgur,
|
pub imgur: ConfigImgur,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct ConfigImgur {
|
pub struct ConfigImgur {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse() -> Result<Config, String> {
|
pub fn parse() -> Result<Config, String> {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod config;
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod config;
|
||||||
|
|
||||||
use cli::cli::parse;
|
use cli::cli::parse;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue