server: add /original/ handler.
This commit is contained in:
parent
720621e19e
commit
113a26dbbb
@ -6,7 +6,7 @@ use std::{error::Error, process::Command, str::FromStr};
|
||||
use rocket::{response::Debug, serde::json::Json, State};
|
||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||
|
||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||
use notmuch::{MessageId, Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||
|
||||
#[get("/")]
|
||||
fn hello() -> &'static str {
|
||||
@ -28,6 +28,17 @@ async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug
|
||||
Ok(Json(res))
|
||||
}
|
||||
|
||||
#[get("/original/<id>")]
|
||||
async fn original(nm: &State<Notmuch>, id: &str) -> Result<Vec<u8>, Debug<NotmuchError>> {
|
||||
let mid = if id.starts_with("id:") {
|
||||
id.to_string()
|
||||
} else {
|
||||
format!("id:{}", id)
|
||||
};
|
||||
let res = nm.show_original(&mid)?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let allowed_origins = AllowedOrigins::all();
|
||||
@ -44,9 +55,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
.to_cors()?;
|
||||
|
||||
rocket::build()
|
||||
.mount("/", routes![hello, search, show])
|
||||
.mount("/", routes![original, hello, search, show])
|
||||
.attach(cors)
|
||||
.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
||||
.manage(Notmuch::default())
|
||||
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user