1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-29 06:20:29 +01:00

Merge pull request #1700 from jjlin/fix-attachment-downloads

Fix attachment downloads
Dieser Commit ist enthalten in:
Daniel García 2021-05-16 14:11:21 +02:00 committet von GitHub
Commit aba5b234af
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 15 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -308,7 +308,8 @@ fn invite_user(data: Json<InviteData>, _token: AdminToken, conn: DbConn) -> Json
} }
user.save(&conn) user.save(&conn)
})().map_err(|e| e.with_code(Status::InternalServerError.code))?; })()
.map_err(|e| e.with_code(Status::InternalServerError.code))?;
Ok(Json(user.to_json(&conn))) Ok(Json(user.to_json(&conn)))
} }

Datei anzeigen

@ -39,6 +39,7 @@ pub fn routes() -> Vec<Route> {
post_ciphers_admin, post_ciphers_admin,
post_ciphers_create, post_ciphers_create,
post_ciphers_import, post_ciphers_import,
get_attachment,
post_attachment, post_attachment,
post_attachment_admin, post_attachment_admin,
post_attachment_share, post_attachment_share,
@ -754,6 +755,15 @@ fn share_cipher_by_uuid(
Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn))) Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn)))
} }
#[get("/ciphers/<uuid>/attachment/<attachment_id>")]
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/<uuid>/attachment", format = "multipart/form-data", data = "<data>")] #[post("/ciphers/<uuid>/attachment", format = "multipart/form-data", data = "<data>")]
fn post_attachment( fn post_attachment(
uuid: String, uuid: String,

Datei anzeigen

@ -55,9 +55,9 @@ fn web_files(p: PathBuf) -> Cached<Option<NamedFile>> {
Cached::long(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join(p)).ok()) Cached::long(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join(p)).ok())
} }
#[get("/attachments/<uuid>/<file..>")] #[get("/attachments/<uuid>/<file_id>")]
fn attachments(uuid: String, file: PathBuf) -> Option<NamedFile> { fn attachments(uuid: String, file_id: String) -> Option<NamedFile> {
NamedFile::open(Path::new(&CONFIG.attachments_folder()).join(uuid).join(file)).ok() NamedFile::open(Path::new(&CONFIG.attachments_folder()).join(uuid).join(file_id)).ok()
} }
#[get("/sends/<send_id>/<file_id>")] #[get("/sends/<send_id>/<file_id>")]