From 9133e2927d3189804431aa013bff2cf14fc812fb Mon Sep 17 00:00:00 2001 From: Jeremy Lin Date: Sat, 15 May 2021 22:46:57 -0700 Subject: [PATCH] Fix attachment downloads Upstream switched to new upload/download APIs. Uploads fall back to the legacy APIs for now, but not downloads apparently. --- src/api/core/ciphers.rs | 10 ++++++++++ src/api/web.rs | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 0e46a1d2..3832aeb4 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -39,6 +39,7 @@ pub fn routes() -> Vec { post_ciphers_admin, post_ciphers_create, post_ciphers_import, + get_attachment, post_attachment, post_attachment_admin, post_attachment_share, @@ -754,6 +755,15 @@ fn share_cipher_by_uuid( Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn))) } +#[get("/ciphers//attachment/")] +fn get_attachment(uuid: String, attachment_id: String, headers: Headers, conn: DbConn) -> JsonResult { + match Attachment::find_by_id(&attachment_id, &conn) { + Some(attachment) if uuid == attachment.cipher_uuid => Ok(Json(attachment.to_json(&headers.host))), + Some(_) => err!("Attachment doesn't belong to cipher"), + None => err!("Attachment doesn't exist"), + } +} + #[post("/ciphers//attachment", format = "multipart/form-data", data = "")] fn post_attachment( uuid: String, diff --git a/src/api/web.rs b/src/api/web.rs index 1416da0d..645f79a7 100644 --- a/src/api/web.rs +++ b/src/api/web.rs @@ -55,9 +55,9 @@ fn web_files(p: PathBuf) -> Cached> { Cached::long(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join(p)).ok()) } -#[get("/attachments//")] -fn attachments(uuid: String, file: PathBuf) -> Option { - NamedFile::open(Path::new(&CONFIG.attachments_folder()).join(uuid).join(file)).ok() +#[get("/attachments//")] +fn attachments(uuid: String, file_id: String) -> Option { + NamedFile::open(Path::new(&CONFIG.attachments_folder()).join(uuid).join(file_id)).ok() } #[get("/sends//")]