Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version = "0.3.2-alpha"
edition = "2021"
description = "Blazingly fast Discloud CLI"
license = "Apache-2.0"
license-file = "LICENSE"
categories = ["command-line-utilities"]
keywords = ["discloud", "cli", "bot", "fast", "discord"]
readme = "README.md"
Expand All @@ -19,9 +18,14 @@ colored = "2.0.0"
dialoguer = "0.10.2"
directories = "4.0.1"
reqwest = { version = "0.11.11", features = ["blocking", "json", "multipart", "rustls-tls"], default-features=false }
sentry = {version = "0.27.0", default-features = false, features = ["rustls", "reqwest"]}
sentry = { version = "0.27.0", default-features = false, features = ["rustls", "reqwest", "tracing"] }
sentry-tracing = "0.27.0"
serde = { version = "1.0.144", features = ["derive"] }
serde-enum-str = "0.2.5"
spinners = "4.1.0"
tracing = "0.1.36"
tracing-subscriber = { version = "0.3.15" }
walkdir = "2.3.2"
zip = "0.6.2"
[features]
sentry_prod = []
3 changes: 3 additions & 0 deletions src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use crate::api_url;

#[tracing::instrument]
pub fn login(token: String) -> std::io::Result<()> {
let token_file = crate::config_dir::get_path(".discloud_token").unwrap();
std::fs::write(token_file, token)?;
Ok(())
}
#[tracing::instrument]
pub fn get_token() -> std::io::Result<String> {
let token_file = crate::config_dir::get_path(".discloud_token").unwrap();
std::fs::read_to_string(token_file)
}
#[tracing::instrument]
pub fn validate_token() -> bool {
match get_token() {
Ok(token) => {
Expand Down
85 changes: 47 additions & 38 deletions src/commands/aboutme.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
use chrono::{Datelike, Timelike};
use colored::Colorize;

pub fn aboutme(){
#[tracing::instrument]
pub fn aboutme() {
let token = super::expect_token();
match crate::entities::user::fetch_user(token.clone()) {
Ok(user) => {
println!("ID: {}", user.user_id.bright_black());
println!("Plan: {}", color_plan(user.plan));
let end_date = user.plan_data_end;
println!("Your plan ends at: {}/{}/{} {}:{}", end_date.day(), end_date.month(), end_date.year(), end_date.hour(), end_date.minute());
println!(" Which means you have {} days left!", user.last_data_left.days.to_string().green().bold());
println!(
"Your plan ends at: {}/{}/{} {}:{}",
end_date.day(),
end_date.month(),
end_date.year(),
end_date.hour(),
end_date.minute()
);
println!(
" Which means you have {} days left!",
user.last_data_left.days.to_string().green().bold()
);
println!("Memory:");
println!(" Total: {}{}", user.total_ram_mb.to_string().green().bold(), "MB".green().bold());
println!(" Used: {}{}", user.ram_used_mb.to_string().green().bold(), "MB".green().bold());
println!(" Available: {}{}", (user.total_ram_mb - user.ram_used_mb).to_string().green().bold(), "MB".green().bold());
println!(
" Total: {}{}",
user.total_ram_mb.to_string().green().bold(),
"MB".green().bold()
);
println!(
" Used: {}{}",
user.ram_used_mb.to_string().green().bold(),
"MB".green().bold()
);
println!(
" Available: {}{}",
(user.total_ram_mb - user.ram_used_mb)
.to_string()
.green()
.bold(),
"MB".green().bold()
);
println!("Locale: {}", user.locale.blue());
}
Err(err) => super::err(&err.to_string())
}
Err(err) => super::err(&err.to_string()),
}
}
#[tracing::instrument]
fn color_plan(plan: String) -> String {
match plan.as_str() {
"Free" => {
plan.bright_black().to_string()
}
"Carbon" => {
plan.bright_black().bold().to_string()
}
"Gold" => {
plan.yellow().bold().to_string()
}
"Platinum" => {
plan.blue().bold().to_string()
}
"Diamond" => {
plan.cyan().bold().to_string()
}
"Ruby" => {
plan.red().bold().to_string()
}
"Sapphire" => {
plan.bright_red().bold().to_string()
}
"Krypton" => {
plan.bright_green().bold().to_string()
}
"Special" => {
plan.bright_cyan().bold().to_string()
}
_ => unreachable!()
}
match plan.as_str() {
"Free" => plan.bright_black().to_string(),
"Carbon" => plan.bright_black().bold().to_string(),
"Gold" => plan.yellow().bold().to_string(),
"Platinum" => plan.blue().bold().to_string(),
"Diamond" => plan.cyan().bold().to_string(),
"Ruby" => plan.red().bold().to_string(),
"Sapphire" => plan.bright_red().bold().to_string(),
"Krypton" => plan.bright_green().bold().to_string(),
"Special" => plan.bright_cyan().bold().to_string(),
_ => unreachable!(),
}
}
1 change: 1 addition & 0 deletions src/commands/apps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use colored::Colorize;

use crate::entities::FetchError;
#[tracing::instrument]
pub fn apps() {
let token = super::expect_token();
match crate::entities::app::App::fetch_all(token.clone()) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/authstatus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::auth;
use std::io::ErrorKind;
#[tracing::instrument]
pub fn authstatus() -> std::io::Result<()> {
match auth::get_token() {
Ok(token) => {
Expand Down
9 changes: 8 additions & 1 deletion src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ use zip::write::FileOptions;
use std::fs::File;
use std::path::{Path, PathBuf};
use walkdir::{DirEntry, WalkDir};
#[tracing::instrument]
fn get_zip_file_path() -> PathBuf {
let mut dst_file = std::env::temp_dir();
dst_file.push("discloud.zip");
dst_file
}
#[tracing::instrument]
pub fn commit() {
let token = super::expect_token();
let app_id = match super::ask_for_app(token.clone(), "commit") {
Expand Down Expand Up @@ -75,6 +77,7 @@ where
Result::Ok(())
}

#[tracing::instrument]
fn zip_dir_to_file(
src_dir: &str,
dst_file: &str,
Expand Down Expand Up @@ -111,10 +114,14 @@ fn zip_dir_to_file(

Ok(())
}
#[tracing::instrument]
fn upload_zip(token: String, app_id: u128) -> Result<(), String> {
let file_path = get_zip_file_path();
let file_path = file_path.to_str().unwrap();
let client = reqwest::blocking::Client::builder().timeout(None).build().unwrap();
let client = reqwest::blocking::Client::builder()
.timeout(None)
.build()
.unwrap();
let form = reqwest::blocking::multipart::Form::new().file("file", file_path);
match form {
Err(err) => Err(format!("Couldn't open zip file: {}", err)),
Expand Down
1 change: 1 addition & 0 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl App {
}
}
}
#[tracing::instrument]
pub fn init() -> std::io::Result<()> {
use dialoguer::Input;
if std::path::Path::new("discloud.config").exists() {
Expand Down
1 change: 1 addition & 0 deletions src/commands/login.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::*;
#[tracing::instrument]
pub fn login(matches: &ArgMatches) -> std::io::Result<()> {
let token = matches.get_one::<String>("token").unwrap().clone();
if let Err(err) = crate::auth::login(token) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/logs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use spinners::{Spinner, Spinners};

#[tracing::instrument]
pub fn logs(){
let token = super::expect_token();
match super::ask_for_app(token.clone(), "show the logs") {
Expand Down
Loading