Clearing Keys + README

This commit is contained in:
2023-10-26 21:37:26 +02:00
parent 2a15a460d0
commit 833960b23f
5 changed files with 121 additions and 48 deletions

View File

@@ -55,7 +55,6 @@ pub async fn get_user_key() {
if key == "" {
let mut username = String::new();
let mut password = String::new();
print!("Username: ");
io::stdout().lock().flush().unwrap();
@@ -65,7 +64,7 @@ pub async fn get_user_key() {
print!("Password: ");
io::stdout().lock().flush().unwrap();
password = read_password().unwrap();
let password = read_password().unwrap();
let key = pastebin::get_user_key(&API_KEY.lock().unwrap(), username, password)
.await
@@ -79,3 +78,19 @@ pub async fn get_user_key() {
USER_KEY.lock().unwrap().push_str(&key);
}
pub fn clear_keys() {
API_KEY.lock().unwrap().clear();
USER_KEY.lock().unwrap().clear();
let home_dir = match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
};
let key_file = home_dir.join(".pastebin_key");
let user_key_file = home_dir.join(".pastebin_userkey");
fs::remove_file(key_file).expect("Error removing API KEY file");
fs::remove_file(user_key_file).expect("Error removing USER KEY file");
}

View File

@@ -4,6 +4,7 @@ use clap::{Parser, Subcommand};
use std::fs;
use std::path::PathBuf;
mod keys;
mod pastebin;
@@ -19,6 +20,7 @@ enum Action {
Create { file_path: std::path::PathBuf },
Delete { paste_id: String },
List { max_results: Option<u16> },
ClearKeys,
}
#[tokio::main]
@@ -32,6 +34,7 @@ async fn main() {
Action::Create { file_path } => create(file_path).await,
Action::Delete { paste_id } => delete(paste_id).await,
Action::List { max_results } => list(max_results).await,
Action::ClearKeys => keys::clear_keys(),
};
}
@@ -64,12 +67,7 @@ async fn delete(paste_id: String) {
println!("{}", resp);
}
async fn edit(paste_id: String, file_path: PathBuf) {
todo!("No offical way to do that yet");
}
async fn list(max_results: Option<u16>) {
let (x, y) = termion::terminal_size().unwrap();
let resp = pastebin::list_pastes(
&keys::API_KEY.lock().unwrap(),
&keys::USER_KEY.lock().unwrap(),
@@ -78,7 +76,7 @@ async fn list(max_results: Option<u16>) {
.await
.unwrap();
let line = "-".repeat(((x - 15) / 2).into());
let line = "-".repeat(5);
println!("{}Top {} pastes{}", line, max_results.unwrap_or(10), line);
for paste in resp {