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::{response::Debug, serde::json::Json, State};
|
||||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||||
|
|
||||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
use notmuch::{MessageId, Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn hello() -> &'static str {
|
fn hello() -> &'static str {
|
||||||
@ -28,6 +28,17 @@ async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug
|
|||||||
Ok(Json(res))
|
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]
|
#[rocket::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let allowed_origins = AllowedOrigins::all();
|
let allowed_origins = AllowedOrigins::all();
|
||||||
@ -44,9 +55,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
.to_cors()?;
|
.to_cors()?;
|
||||||
|
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.mount("/", routes![hello, search, show])
|
.mount("/", routes![original, hello, search, show])
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
.manage(Notmuch::default())
|
||||||
|
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
||||||
.launch()
|
.launch()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user