mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-03 09:39:15 +02:00
Show metadata properties with info CLI command, check if file exists
This commit is contained in:
parent
349e62ed1c
commit
a7827197a7
7 changed files with 142 additions and 10 deletions
|
@ -18,6 +18,10 @@ use crypto::sig::signature_encoded;
|
|||
use ext::status_code::StatusCodeExt;
|
||||
use file::remote_file::RemoteFile;
|
||||
use reader::{EncryptedFileWriter, ProgressReporter, ProgressWriter};
|
||||
use super::exists::{
|
||||
Error as ExistsError,
|
||||
Exists as ExistsAction,
|
||||
};
|
||||
use super::metadata::{
|
||||
Error as MetadataError,
|
||||
Metadata as MetadataAction,
|
||||
|
@ -55,6 +59,27 @@ impl<'a> Download<'a> {
|
|||
client: &Client,
|
||||
reporter: Arc<Mutex<ProgressReporter>>,
|
||||
) -> Result<(), Error> {
|
||||
// Make sure the given file exists
|
||||
let exist_response = ExistsAction::new(&self.file)
|
||||
.invoke(&client)?;
|
||||
|
||||
// Return an error if the file does not exist
|
||||
if !exist_response.exists() {
|
||||
return Err(Error::Expired);
|
||||
}
|
||||
|
||||
// Make sure a password is given when it is required
|
||||
let has_password = self.password.is_some();
|
||||
if has_password != exist_response.has_password() {
|
||||
if has_password {
|
||||
// TODO: show a proper message here
|
||||
println!("file not password protected, ignoring password");
|
||||
} else {
|
||||
// TODO: show a propper error here, or prompt for the password
|
||||
panic!("password required");
|
||||
}
|
||||
}
|
||||
|
||||
// Create a key set for the file
|
||||
let mut key = KeySet::from(self.file, self.password.as_ref());
|
||||
|
||||
|
@ -232,6 +257,11 @@ impl<'a> Download<'a> {
|
|||
|
||||
#[derive(Fail, Debug)]
|
||||
pub enum Error {
|
||||
/// An error occurred while checking whether the file exists on the
|
||||
/// server.
|
||||
#[fail(display = "Failed to check whether the file exists")]
|
||||
Exists(#[cause] ExistsError),
|
||||
|
||||
/// An error occurred while fetching the metadata of the file.
|
||||
/// This step is required in order to succsessfully decrypt the
|
||||
/// file that will be downloaded.
|
||||
|
@ -257,6 +287,12 @@ pub enum Error {
|
|||
File(String, #[cause] FileError),
|
||||
}
|
||||
|
||||
impl From<ExistsError> for Error {
|
||||
fn from(err: ExistsError) -> Error {
|
||||
Error::Exists(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MetadataError> for Error {
|
||||
fn from(err: MetadataError) -> Error {
|
||||
Error::Meta(err)
|
||||
|
|
|
@ -49,8 +49,9 @@ impl<'a> Exists<'a> {
|
|||
}
|
||||
|
||||
// Parse the response
|
||||
let response = response.json::<ExistsResponse>()
|
||||
let mut response = response.json::<ExistsResponse>()
|
||||
.map_err(|_| Error::Malformed)?;
|
||||
response.set_exists(true);
|
||||
|
||||
// TODO: fetch the metadata nonce from the response headers
|
||||
|
||||
|
@ -84,6 +85,11 @@ impl ExistsResponse {
|
|||
self.exists
|
||||
}
|
||||
|
||||
/// Set whether the remote file exists.
|
||||
pub fn set_exists(&mut self, exists: bool) {
|
||||
self.exists = exists;
|
||||
}
|
||||
|
||||
/// Whether the remote file is protected by a password.
|
||||
pub fn has_password(&self) -> bool {
|
||||
self.has_password
|
||||
|
|
|
@ -52,6 +52,11 @@ impl Metadata {
|
|||
&self.name
|
||||
}
|
||||
|
||||
/// Get the file MIME type.
|
||||
pub fn mime(&self) -> &str {
|
||||
&self.mime
|
||||
}
|
||||
|
||||
/// Get the input vector
|
||||
// TODO: use an input vector length from a constant
|
||||
pub fn iv(&self) -> [u8; 12] {
|
||||
|
|
|
@ -133,6 +133,11 @@ impl RemoteFile {
|
|||
))
|
||||
}
|
||||
|
||||
/// Get the file ID.
|
||||
pub fn id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
|
||||
/// Get the raw secret.
|
||||
pub fn secret_raw(&self) -> &Vec<u8> {
|
||||
// A secret must have been set
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue