Compare commits
No commits in common. "a6e827cd789df596be85fce5565146260dd35e8a" and "e8709b79ce2af962fe3f12384f2ee0673444852e" have entirely different histories.
a6e827cd78
...
e8709b79ce
4 changed files with 36 additions and 103 deletions
44
Cargo.lock
generated
44
Cargo.lock
generated
|
|
@ -152,19 +152,6 @@ version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "console"
|
|
||||||
version = "0.15.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
|
|
||||||
dependencies = [
|
|
||||||
"encode_unicode",
|
|
||||||
"libc",
|
|
||||||
"once_cell",
|
|
||||||
"unicode-width",
|
|
||||||
"windows-sys 0.59.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cookie"
|
name = "cookie"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
|
|
@ -222,17 +209,6 @@ dependencies = [
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dialoguer"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de"
|
|
||||||
dependencies = [
|
|
||||||
"console",
|
|
||||||
"shell-words",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-next"
|
name = "dirs-next"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
|
@ -274,12 +250,6 @@ dependencies = [
|
||||||
"litrs",
|
"litrs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "encode_unicode"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_filter"
|
name = "env_filter"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
|
@ -796,12 +766,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shell-words"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|
@ -813,9 +777,7 @@ name = "shrupl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"console",
|
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"dialoguer",
|
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -937,12 +899,6 @@ version = "1.0.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-width"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ description = "ShrUpl is a tool to upload files to a Sharry Instance through a p
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.38", features = ["derive"] }
|
clap = { version = "4.5.38", features = ["derive"] }
|
||||||
console = { version = "0.15.11", default-features = false }
|
|
||||||
ctrlc = { version = "3.4.7", features = ["termination"] }
|
ctrlc = { version = "3.4.7", features = ["termination"] }
|
||||||
dialoguer = { version = "0.11.0", default-features = false }
|
|
||||||
dirs-next = "2.0.0"
|
dirs-next = "2.0.0"
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,12 @@ impl AppState {
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_args(args: &Cli, http: &ureq::Agent) -> Result<Self, ureq::Error> {
|
pub fn from_args(args: &Cli, http: &ureq::Agent) -> Result<Self, String> {
|
||||||
let file_name = Self::cache_file(args);
|
let file_name = Self::cache_file(args);
|
||||||
let alias = args.get_alias();
|
let alias = args.get_alias();
|
||||||
|
|
||||||
let share = Share::create(http, &alias, args.get_share_request())?;
|
let share = Share::create(http, &alias, args.get_share_request())
|
||||||
|
.map_err(|e| format!("could not create share: {e}"))?;
|
||||||
|
|
||||||
let files: VecDeque<_> = args.files.clone().into_iter().map(FileState::C).collect();
|
let files: VecDeque<_> = args.files.clone().into_iter().map(FileState::C).collect();
|
||||||
|
|
||||||
|
|
@ -95,7 +96,11 @@ impl AppState {
|
||||||
.start_upload(http, &self.alias, &self.share)
|
.start_upload(http, &self.alias, &self.share)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Some(FileState::U(uploading)) => uploading,
|
Some(FileState::U(uploading)) => uploading,
|
||||||
None => return Ok(None),
|
None => {
|
||||||
|
self.share.notify(http, &self.alias).unwrap();
|
||||||
|
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("{uploading} chunk {chunk_size}");
|
debug!("{uploading} chunk {chunk_size}");
|
||||||
|
|
@ -111,9 +116,7 @@ impl AppState {
|
||||||
}
|
}
|
||||||
ChunkState::Finished(path) => {
|
ChunkState::Finished(path) => {
|
||||||
debug!("Finished {:?}!", path.display());
|
debug!("Finished {:?}!", path.display());
|
||||||
self.share.notify(http, &self.alias).unwrap();
|
Ok(Some(()))
|
||||||
|
|
||||||
Ok(self.files.front().map(drop))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -125,14 +128,14 @@ impl AppState {
|
||||||
let mut file = fs::File::create(&self.file_name)?;
|
let mut file = fs::File::create(&self.file_name)?;
|
||||||
file.write_all(json.as_bytes())?;
|
file.write_all(json.as_bytes())?;
|
||||||
|
|
||||||
trace!("updated {:?}", self.file_name.display());
|
trace!("successfully saved AppState");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(self) -> io::Result<()> {
|
pub fn clear(self) -> io::Result<()> {
|
||||||
fs::remove_file(&self.file_name)?;
|
fs::remove_file(self.file_name)?;
|
||||||
|
|
||||||
trace!("removed {:?}", self.file_name.display());
|
trace!("successfully cleared AppState");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
72
src/main.rs
72
src/main.rs
|
|
@ -11,8 +11,6 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::style;
|
|
||||||
use dialoguer::{Confirm, theme::ColorfulTheme};
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use ureq::Agent;
|
use ureq::Agent;
|
||||||
|
|
||||||
|
|
@ -20,14 +18,11 @@ use appstate::AppState;
|
||||||
use cli::Cli;
|
use cli::Cli;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let stop = Arc::new(AtomicBool::new(false));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
|
let r = running.clone();
|
||||||
|
|
||||||
let stop_ctrlc = stop.clone();
|
ctrlc::set_handler(move || r.store(false, Ordering::SeqCst))
|
||||||
ctrlc::set_handler(move || {
|
.expect("Error setting Ctrl-C handler");
|
||||||
stop_ctrlc.store(true, Ordering::SeqCst);
|
|
||||||
info!("stopping after chunk ...");
|
|
||||||
})
|
|
||||||
.expect("Error setting Ctrl-C handler");
|
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
|
@ -40,54 +35,35 @@ fn main() {
|
||||||
.build()
|
.build()
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let mut state = AppState::try_resume(&args)
|
let mut state = match AppState::try_resume(&args) {
|
||||||
.and_then(|state| {
|
Some(state) => {
|
||||||
Confirm::with_theme(&ColorfulTheme::default())
|
info!("loaded state: {state:?}");
|
||||||
.with_prompt("Previous operation found. Continue?")
|
state
|
||||||
.default(true)
|
}
|
||||||
.interact()
|
None => AppState::from_args(&args, &agent).unwrap_or_else(|e| {
|
||||||
.map_or(None, |b| b.then_some(state))
|
error!("could not create new state: {e}");
|
||||||
})
|
exit(1);
|
||||||
.unwrap_or_else(|| match AppState::from_args(&args, &agent) {
|
}),
|
||||||
Ok(state) => {
|
};
|
||||||
state.save().unwrap();
|
|
||||||
state
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
match e {
|
|
||||||
ureq::Error::StatusCode(403) => println!(
|
|
||||||
"{} probably wrong: {}",
|
|
||||||
style("Error!").red(),
|
|
||||||
style("Alias ID").cyan()
|
|
||||||
),
|
|
||||||
ureq::Error::Io(e) => println!(
|
|
||||||
"{} probably wrong: {} – {}",
|
|
||||||
style("Error!").red(),
|
|
||||||
style("URL").cyan(),
|
|
||||||
style(e).yellow()
|
|
||||||
),
|
|
||||||
_ => error!("unknown error: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("could not create new state!");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
info!("continuing with state: {state:?}");
|
info!("continuing with state: {state:?}");
|
||||||
|
state.save().unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match state.upload_chunk(&agent, args.chunk_size * 1024 * 1024) {
|
match state.upload_chunk(&agent, args.chunk_size * 1024 * 1024) {
|
||||||
|
Ok(None) => break,
|
||||||
Err(e) => error!("error: {e:?}"),
|
Err(e) => error!("error: {e:?}"),
|
||||||
Ok(None) => {
|
|
||||||
info!("all uploads done");
|
|
||||||
state.clear().unwrap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
state.save().unwrap();
|
state.save().unwrap();
|
||||||
stop.load(Ordering::SeqCst).then(|| exit(0));
|
|
||||||
|
if !running.load(Ordering::SeqCst) {
|
||||||
|
info!("terminating ...");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info!("uploads done");
|
||||||
|
state.clear().unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue