server: add URL for downloading attachments.

This commit is contained in:
Bill Thiede 2021-11-08 21:06:45 -08:00
parent bd14616069
commit f809f89dd0

View File

@ -32,6 +32,21 @@ async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug
Ok(Json(res))
}
#[get("/original/<id>/part/<part>")]
async fn original_part(
nm: &State<Notmuch>,
id: &str,
part: usize,
) -> Result<Vec<u8>, Debug<NotmuchError>> {
let mid = if id.starts_with("id:") {
id.to_string()
} else {
format!("id:{}", id)
};
let res = nm.show_original_part(&mid, part)?;
Ok(res)
}
#[get("/original/<id>")]
async fn original(nm: &State<Notmuch>, id: &str) -> Result<Plain<Vec<u8>>, Debug<NotmuchError>> {
let mid = if id.starts_with("id:") {
@ -59,10 +74,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
.to_cors()?;
rocket::build()
.mount("/", routes![original, hello, search, show])
.mount("/", routes![original_part, original, hello, search, show])
.attach(cors)
.manage(Notmuch::default())
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
//.manage(Notmuch::default())
.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
.launch()
.await?;