mirror of
https://github.com/MedzikUser/imgurs
synced 2024-08-15 00:03:19 +00:00
Compare commits
30 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b6ef4241ca | ||
|
6d6cbbd4b0 | ||
|
723bf26dbd | ||
|
56cbd96053 | ||
|
af0864d272 | ||
|
e782617f08 | ||
|
7062046679 | ||
|
9ba2233734 | ||
|
044fa6525d | ||
|
f6d8e906fb | ||
|
47b6225280 | ||
|
e9a7108f90 | ||
|
0398f7f675 | ||
|
300fa61a65 | ||
|
0ad55015ac | ||
|
965c4407f1 | ||
|
80292730f3 | ||
|
304034f037 | ||
|
b6e715accf | ||
|
d29b299a4b | ||
|
c08e640421 | ||
|
60119be30b | ||
|
986a3b365c | ||
|
25cc96774c | ||
|
111fef82d1 | ||
|
5d5beaecd8 | ||
|
89a7969353 | ||
|
25190ba5c1 | ||
|
012784a352 | ||
|
1bd632e906 |
13 changed files with 1493 additions and 915 deletions
38
CHANGELOG.md
38
CHANGELOG.md
|
@ -9,6 +9,32 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.11.3] - 2024-04-11
|
||||
- Updated dependencies
|
||||
- Replaced url validation with url crate in imgurs-cli
|
||||
|
||||
## [0.11.2] - 2023-06-22
|
||||
- Updated dependencies
|
||||
- Fix deprecation warning of base64 crate.
|
||||
|
||||
## [0.11.1] - 2022-12-11
|
||||
### Fixed
|
||||
- `album_title` can be null, `account_id` can be null, string or number #92, thanks to @NotNorom
|
||||
|
||||
### Changed
|
||||
- Updated dependencies
|
||||
|
||||
## [0.11.0] - 2022-11-07
|
||||
### Added
|
||||
- Added `with_http_client` method to ImgurClient #87, thanks to @NotNorom
|
||||
|
||||
### Changed
|
||||
- Updated crate arboard to v3
|
||||
- Updated crate simple_logger to v4
|
||||
|
||||
## [0.10.0] - 2022-10-01
|
||||
- add configuration for tls (rustls-tls or native-tls)
|
||||
|
||||
## [0.9.1] - 2022-09-22
|
||||
- delete debug info from cli in release build
|
||||
|
||||
|
@ -136,8 +162,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
- upload image
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.8.0...HEAD
|
||||
[0.7.4]: https://github.com/MedzikUser/imgurs/commits/v0.8.0
|
||||
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.11.3...HEAD
|
||||
[0.11.3]: https://github.com/MedzikUser/imgurs/commits/v0.11.3
|
||||
[0.11.2]: https://github.com/MedzikUser/imgurs/commits/v0.11.2
|
||||
[0.11.1]: https://github.com/MedzikUser/imgurs/commits/v0.11.1
|
||||
[0.11.0]: https://github.com/MedzikUser/imgurs/commits/v0.11.0
|
||||
[0.10.0]: https://github.com/MedzikUser/imgurs/commits/v0.10.0
|
||||
[0.9.1]: https://github.com/MedzikUser/imgurs/commits/v0.9.1
|
||||
[0.9.0]: https://github.com/MedzikUser/imgurs/commits/v0.9.0
|
||||
[0.8.1]: https://github.com/MedzikUser/imgurs/commits/v0.8.1
|
||||
[0.8.0]: https://github.com/MedzikUser/imgurs/commits/v0.8.0
|
||||
[0.7.4]: https://github.com/MedzikUser/imgurs/commits/v0.7.4
|
||||
[0.7.3]: https://github.com/MedzikUser/imgurs/commits/v0.7.3
|
||||
[0.7.2]: https://github.com/MedzikUser/imgurs/commits/v0.7.2
|
||||
|
|
2177
Cargo.lock
generated
2177
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
34
Cargo.toml
34
Cargo.toml
|
@ -4,20 +4,21 @@ resolver = "2"
|
|||
|
||||
[package]
|
||||
name = "imgurs"
|
||||
version = "0.9.1"
|
||||
version = "0.11.3"
|
||||
description = "API for Imgur"
|
||||
license = "BSD-3-Clause"
|
||||
authors = ["MedzikUser <nivua1fn@duck.com>"]
|
||||
homepage = "https://github.com/MedzikUser/imgurs"
|
||||
repository = "https://github.com/MedzikUser/imgurs.git"
|
||||
authors = ["M3DZIK <me@medzik.dev>"]
|
||||
homepage = "https://github.com/M3DZIK/imgurs"
|
||||
repository = "https://github.com/M3DZIK/imgurs.git"
|
||||
keywords = ["imgur", "imgur-api", "image", "image-upload"]
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
default = ["imgur"]
|
||||
full = ["imgur", "null_pointer"]
|
||||
default = ["imgur", "rustls-tls"]
|
||||
full = ["imgur"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
imgur = []
|
||||
null_pointer = []
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
@ -25,13 +26,18 @@ opt-level = 'z'
|
|||
codegen-units = 1
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.13"
|
||||
notify-rust = "4.5"
|
||||
validator = "0.16"
|
||||
thiserror = "1.0"
|
||||
serde_json = "1.0"
|
||||
# HTTP
|
||||
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart"] }
|
||||
# Request
|
||||
base64 = "0.22"
|
||||
url = "2.5.0" # validate url address
|
||||
# Response
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls", "multipart"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
# Errors
|
||||
thiserror = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.21", features = ["macros", "rt-multi-thread"] }
|
||||
# Async tests
|
||||
tokio = { version = "1.37", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
[total-lines]: https://img.shields.io/tokei/lines/github/MedzikUser/HomeDisk?style=for-the-badge&logo=github&color=fede00
|
||||
[code-size]: https://img.shields.io/github/languages/code-size/MedzikUser/HomeDisk?style=for-the-badge&color=c8df52&logo=github
|
||||
[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
|
||||
[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
|
||||
[ci]: https://img.shields.io/github/workflow/status/MedzikUser/rust-crypto-utils/Rust/main?style=for-the-badge&logo=github
|
||||
|
||||
# Imgurs - CLI and Library for Imgur API
|
||||
|
||||
[![total-lines]](https://github.com/MedzikUser/HomeDisk)
|
||||
[![code-size]](https://github.com/MedzikUser/HomeDisk)
|
||||
[![crates-io]](https://crates.io/crates/imgurs)
|
||||
[![docs-rs]](https://docs.rs/imgurs)
|
||||
[![ci]](https://github.com/MedzikUser/imgurs/actions/workflows/rust.yml)
|
||||
|
||||
## Screenshots
|
||||
|
||||
|
@ -74,4 +68,4 @@ Download imgurs-windows.exe from [the releases page](https://github.com/MedzikUs
|
|||
### **Compile with Cargo**
|
||||
Make sure you have a recent version of Rust. Then you can run
|
||||
|
||||
cargo install imgurs
|
||||
cargo install imgurs-cli
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
[package]
|
||||
name = "imgurs-cli"
|
||||
version = "0.9.1"
|
||||
version = "0.11.3"
|
||||
description = "CLI for Imgur"
|
||||
license = "BSD-3-Clause"
|
||||
authors = ["MedzikUser <nivua1fn@duck.com>"]
|
||||
homepage = "https://github.com/MedzikUser/imgurs"
|
||||
repository = "https://github.com/MedzikUser/imgurs.git"
|
||||
authors = ["M3DZIK <me@medzik.dev>"]
|
||||
homepage = "https://github.com/M3DZIK/imgurs"
|
||||
repository = "https://github.com/M3DZIK/imgurs.git"
|
||||
keywords = ["imgur", "imgur-api", "image", "image-upload"]
|
||||
categories = ["command-line-utilities"]
|
||||
edition = "2021"
|
||||
|
@ -15,21 +15,32 @@ name = "imgurs"
|
|||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
# Async runtime
|
||||
tokio = { version = "1.37", features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
# CLI
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
clap_complete = "4.5"
|
||||
clap_mangen = "0.2"
|
||||
|
||||
# Errors
|
||||
anyhow = "1.0"
|
||||
clap = { version = "3.2", features = ["derive"] }
|
||||
clap_complete = "3.2"
|
||||
clap_mangen = "0.1"
|
||||
chrono = "0.4"
|
||||
colored = "2.0"
|
||||
notify-rust = "4.5"
|
||||
better-panic = "0.3"
|
||||
dirs = "4.0"
|
||||
simple_logger = "2.3"
|
||||
toml = "0.5"
|
||||
|
||||
# Logger
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
simple_logger = "4.3"
|
||||
colored = "2.1"
|
||||
|
||||
# Config
|
||||
toml = "0.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = { version = "1.21", features = ["macros", "rt-multi-thread"] }
|
||||
imgurs = { path = "..", version = "0.9.0", features = ["full"] }
|
||||
|
||||
# Other
|
||||
chrono = "0.4" # parse upload date
|
||||
notify-rust = "4.11" # send notification after upload
|
||||
dirs = "5.0" # get system configuration directory
|
||||
|
||||
imgurs = { path = "..", version = "0.11.0", features = ["full"] }
|
||||
|
||||
[target.'cfg(not(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten")))))'.dependencies]
|
||||
arboard = "2.1"
|
||||
arboard = "3.3" # copy url to clipboard
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use super::Config;
|
||||
|
||||
use colored::Colorize;
|
||||
use dirs::config_dir;
|
||||
use log::warn;
|
||||
use std::{
|
||||
fs::{create_dir_all, read_to_string, File},
|
||||
io::{self, Write as _},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use colored::Colorize;
|
||||
use dirs::config_dir;
|
||||
use log::warn;
|
||||
use toml::from_str as toml_from_str;
|
||||
|
||||
use super::Config;
|
||||
|
||||
/// Configuration file path (in system config directory).
|
||||
const CONFIG_DIR: &str = "/imgurs/config.toml";
|
||||
|
||||
|
|
|
@ -4,12 +4,13 @@ mod delete_image;
|
|||
mod info_image;
|
||||
mod upload_image;
|
||||
|
||||
pub use self::{clipboard::*, credits::*, delete_image::*, info_image::*, upload_image::*};
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
use chrono::{prelude::DateTime, Utc};
|
||||
use colored::Colorize;
|
||||
use imgurs::ImageInfo;
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
pub use self::{clipboard::*, credits::*, delete_image::*, info_image::*, upload_image::*};
|
||||
|
||||
// print image information from imgur
|
||||
pub fn print_image_info(i: &ImageInfo) {
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
use std::io::stdout;
|
||||
|
||||
use crate::imgur::*;
|
||||
use clap::{Command, CommandFactory, Parser};
|
||||
use clap_complete::{generate, Generator, Shell};
|
||||
use imgurs::ImgurClient;
|
||||
use simple_logger::SimpleLogger;
|
||||
|
||||
use crate::imgur::*;
|
||||
|
||||
mod config;
|
||||
mod imgur;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
name = "imgurs",
|
||||
about = "Imgur API CLI", long_about = None,
|
||||
about = "Imgur API CLI",
|
||||
long_about = env!("CARGO_PKG_DESCRIPTION"),
|
||||
version = env!("CARGO_PKG_VERSION"),
|
||||
)]
|
||||
enum Cli {
|
||||
|
@ -41,7 +43,6 @@ enum Cli {
|
|||
#[tokio::main]
|
||||
async fn main() {
|
||||
SimpleLogger::new().init().unwrap();
|
||||
better_panic::install();
|
||||
|
||||
// parse config file
|
||||
let config = config::toml::parse();
|
||||
|
@ -54,7 +55,7 @@ async fn main() {
|
|||
match args {
|
||||
Cli::Credits => credits(client).await,
|
||||
|
||||
Cli::Upload { path } => upload_image(client, path.to_string()).await,
|
||||
Cli::Upload { path } => upload_image(client, path).await,
|
||||
|
||||
Cli::Delete { delete_hash } => delete_image(client, delete_hash.to_string()).await,
|
||||
|
||||
|
@ -68,14 +69,14 @@ async fn main() {
|
|||
}
|
||||
|
||||
print_completions(shell, &mut app)
|
||||
}
|
||||
},
|
||||
|
||||
Cli::Manpage => {
|
||||
let clap_app = Cli::command();
|
||||
let man = clap_mangen::Man::new(clap_app);
|
||||
|
||||
man.render(&mut stdout())
|
||||
.expect("failed to generate man page");
|
||||
}
|
||||
.expect("Failed to generate man page");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
11
rustfmt.toml
Normal file
11
rustfmt.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
# https://rust-lang.github.io/rustfmt
|
||||
|
||||
# stable
|
||||
edition = "2021"
|
||||
newline_style = "Unix"
|
||||
match_block_trailing_comma = true
|
||||
|
||||
# nightly
|
||||
group_imports = "StdExternalCrate"
|
||||
imports_granularity = "Crate"
|
||||
format_code_in_doc_comments = true
|
|
@ -18,7 +18,7 @@ pub struct AlbumInfoData {
|
|||
/// Album ID
|
||||
pub id: String,
|
||||
/// Title of the album
|
||||
pub title: String,
|
||||
pub title: Option<String>,
|
||||
/// Description of the album
|
||||
pub description: Option<String>,
|
||||
pub datetime: i64,
|
||||
|
@ -27,7 +27,7 @@ pub struct AlbumInfoData {
|
|||
pub cover_width: i64,
|
||||
pub cover_height: i64,
|
||||
pub account_url: Option<String>,
|
||||
pub account_id: Option<String>,
|
||||
pub account_id: Option<AccountId>,
|
||||
pub privacy: String,
|
||||
pub layout: String,
|
||||
pub views: i64,
|
||||
|
@ -45,6 +45,13 @@ pub struct AlbumInfoData {
|
|||
pub ad_config: AdConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
#[serde(untagged)]
|
||||
pub enum AccountId {
|
||||
String(String),
|
||||
Int(i64),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct AdConfig {
|
||||
#[serde(rename = "safeFlags")]
|
||||
|
|
|
@ -4,10 +4,9 @@ macro_rules! api_url (
|
|||
);
|
||||
);
|
||||
|
||||
pub(crate) use api_url;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub(crate) use api_url;
|
||||
use reqwest::Client;
|
||||
|
||||
/// Imgur Client
|
||||
|
|
|
@ -9,6 +9,7 @@ pub(crate) use client::api_url;
|
|||
pub use client::ImgurClient;
|
||||
pub use image_type::*;
|
||||
pub use send_api_request::*;
|
||||
use url::Url;
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
|
@ -25,6 +26,25 @@ impl ImgurClient {
|
|||
ImgurClient { client_id, client }
|
||||
}
|
||||
|
||||
/// Create a new Imgur Client with the provided `reqwest::Client`
|
||||
///
|
||||
/// This allows for customization of the http client settings like timeout or the user agent.
|
||||
/// ```
|
||||
/// use imgurs::ImgurClient;
|
||||
/// use reqwest::Client;
|
||||
///
|
||||
/// let http_client = Client::builder().build().unwrap();
|
||||
///
|
||||
/// let client = ImgurClient::with_http_client("3e3ce0d7ac14d56", http_client);
|
||||
/// ```
|
||||
pub fn with_http_client(client_id: &str, http_client: reqwest::Client) -> Self {
|
||||
let client_id = client_id.to_string();
|
||||
ImgurClient {
|
||||
client_id,
|
||||
client: http_client,
|
||||
}
|
||||
}
|
||||
|
||||
/// Upload image to Imgur
|
||||
/// ```
|
||||
/// use imgurs::ImgurClient;
|
||||
|
@ -33,19 +53,24 @@ impl ImgurClient {
|
|||
/// async fn main() {
|
||||
/// let client = ImgurClient::new("3e3ce0d7ac14d56");
|
||||
///
|
||||
/// client.upload_image("https://i.imgur.com/lFaGr1x.png").await.expect("upload image");
|
||||
/// client
|
||||
/// .upload_image("https://i.imgur.com/lFaGr1x.png")
|
||||
/// .await
|
||||
/// .expect("upload image");
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn upload_image(&self, path: &str) -> Result<ImageInfo> {
|
||||
use base64::prelude::{Engine, BASE64_STANDARD};
|
||||
|
||||
let mut image = path.to_string();
|
||||
|
||||
// check if the specified file exists if not then check if it is a url
|
||||
if std::path::Path::new(path).exists() {
|
||||
let bytes = std::fs::read(path)?;
|
||||
image = base64::encode(bytes)
|
||||
image = BASE64_STANDARD.encode(bytes)
|
||||
}
|
||||
// validate url adress
|
||||
else if !validator::validate_url(path) {
|
||||
else if Url::parse(path).is_err() {
|
||||
Err(Error::InvalidUrlOrFile(path.to_string()))?;
|
||||
}
|
||||
|
||||
|
@ -60,10 +85,16 @@ impl ImgurClient {
|
|||
/// async fn main() {
|
||||
/// let client = ImgurClient::new("3e3ce0d7ac14d56");
|
||||
///
|
||||
/// let image = client.upload_image("https://i.imgur.com/lFaGr1x.png").await.expect("upload image");
|
||||
/// let image = client
|
||||
/// .upload_image("https://i.imgur.com/lFaGr1x.png")
|
||||
/// .await
|
||||
/// .expect("upload image");
|
||||
/// let deletehash = image.data.deletehash.unwrap();
|
||||
///
|
||||
/// client.delete_image(&deletehash).await.expect("delete image");
|
||||
/// client
|
||||
/// .delete_image(&deletehash)
|
||||
/// .await
|
||||
/// .expect("delete image");
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn delete_image(&self, delete_hash: &str) -> Result<()> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! [![github]](https://github.com/MedzikUser/imgurs)
|
||||
//! [![github]](https://github.com/M3DZIK/imgurs)
|
||||
//! [![crates-io]](https://crates.io/crates/imgurs)
|
||||
//! [![docs-rs]](https://docs.rs/imgurs)
|
||||
//!
|
||||
|
@ -19,7 +19,7 @@
|
|||
//! your application, simply add it to your project's `Cargo.toml`.
|
||||
//! ```toml
|
||||
//! [dependencies]
|
||||
//! imgurs = "0.8.0"
|
||||
//! imgurs = "0.11.3"
|
||||
//! ```
|
||||
//!
|
||||
//! # Example Usage
|
||||
|
@ -40,7 +40,10 @@
|
|||
//! let client = ImgurClient::new("client_id");
|
||||
//!
|
||||
//! // From URL
|
||||
//! let info = client.upload_image("https://i.imgur.com/lFaGr1x.png").await.unwrap();
|
||||
//! let info = client
|
||||
//! .upload_image("https://i.imgur.com/lFaGr1x.png")
|
||||
//! .await
|
||||
//! .unwrap();
|
||||
//! println!("{:?}", info);
|
||||
//!
|
||||
//! // From File
|
||||
|
|
Loading…
Reference in a new issue