mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 21:26:38 +00:00
Attachment::save()
returns Result instead of bool (#161)
Returning a result instead of a bool as per #6
This commit is contained in:
parent
062ae4dd59
commit
fe473b9e75
@ -375,11 +375,11 @@ fn put_cipher_share_seleted(data: JsonUpcase<ShareSelectedCipherData>, headers:
|
|||||||
if data.Ciphers.len() == 0 {
|
if data.Ciphers.len() == 0 {
|
||||||
err!("You must select at least one cipher.")
|
err!("You must select at least one cipher.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.CollectionIds.len() == 0 {
|
if data.CollectionIds.len() == 0 {
|
||||||
err!("You must select at least one collection.")
|
err!("You must select at least one collection.")
|
||||||
}
|
}
|
||||||
|
|
||||||
for cipher in data.Ciphers.iter() {
|
for cipher in data.Ciphers.iter() {
|
||||||
match cipher.Id {
|
match cipher.Id {
|
||||||
Some(ref id) => cipher_ids.push(id.to_string()),
|
Some(ref id) => cipher_ids.push(id.to_string()),
|
||||||
@ -388,7 +388,7 @@ fn put_cipher_share_seleted(data: JsonUpcase<ShareSelectedCipherData>, headers:
|
|||||||
}
|
}
|
||||||
|
|
||||||
let attachments = Attachment::find_by_ciphers(cipher_ids, &conn);
|
let attachments = Attachment::find_by_ciphers(cipher_ids, &conn);
|
||||||
|
|
||||||
if attachments.len() > 0 {
|
if attachments.len() > 0 {
|
||||||
err!("Ciphers should not have any attachments.")
|
err!("Ciphers should not have any attachments.")
|
||||||
}
|
}
|
||||||
@ -492,7 +492,10 @@ fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers
|
|||||||
};
|
};
|
||||||
|
|
||||||
let attachment = Attachment::new(file_name, cipher.uuid.clone(), name, size);
|
let attachment = Attachment::new(file_name, cipher.uuid.clone(), name, size);
|
||||||
attachment.save(&conn);
|
match attachment.save(&conn) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(_) => println!("Error: failed to save attachment")
|
||||||
|
};
|
||||||
}).expect("Error processing multipart data");
|
}).expect("Error processing multipart data");
|
||||||
|
|
||||||
Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn)))
|
Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn)))
|
||||||
@ -654,7 +657,7 @@ fn delete_all(data: JsonUpcase<PasswordData>, headers: Headers, conn: DbConn) ->
|
|||||||
for f in Folder::find_by_user(&user.uuid, &conn) {
|
for f in Folder::find_by_user(&user.uuid, &conn) {
|
||||||
if f.delete(&conn).is_err() {
|
if f.delete(&conn).is_err() {
|
||||||
err!("Failed deleting folder")
|
err!("Failed deleting folder")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -53,13 +53,11 @@ use db::schema::attachments;
|
|||||||
|
|
||||||
/// Database methods
|
/// Database methods
|
||||||
impl Attachment {
|
impl Attachment {
|
||||||
pub fn save(&self, conn: &DbConn) -> bool {
|
pub fn save(&self, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::replace_into(attachments::table)
|
diesel::replace_into(attachments::table)
|
||||||
.values(self)
|
.values(self)
|
||||||
.execute(&**conn) {
|
.execute(&**conn)
|
||||||
Ok(1) => true, // One row inserted
|
.and(Ok(()))
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
@ -67,7 +65,7 @@ impl Attachment {
|
|||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
let mut retries = 10;
|
let mut retries = 10;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match diesel::delete(
|
match diesel::delete(
|
||||||
attachments::table.filter(
|
attachments::table.filter(
|
||||||
|
Loading…
Reference in New Issue
Block a user