This commit is contained in:
2023-07-15 16:58:15 -07:00
parent 458bd356dd
commit 39bef1ea87
3 changed files with 51 additions and 8 deletions

View File

@@ -1,10 +1,12 @@
#[macro_use]
extern crate rocket;
mod error;
mod nm;
use std::{error::Error, io::Cursor, str::FromStr};
use glog::Flags;
use notmuch::{Notmuch, NotmuchError, ThreadSet};
use notmuch::{Notmuch, NotmuchError};
use rocket::{
http::{ContentType, Header},
request::Request,
@@ -14,6 +16,8 @@ use rocket::{
};
use rocket_cors::{AllowedHeaders, AllowedOrigins};
use crate::error::ServerError;
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
@@ -52,8 +56,11 @@ async fn search(
}
#[get("/show/<query>")]
async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
let res = nm.show(query)?;
async fn show(
nm: &State<Notmuch>,
query: &str,
) -> Result<Json<Vec<shared::Message>>, Debug<ServerError>> {
let res = nm::threadset_to_messages(nm.show(query).map_err(|e| -> ServerError { e.into() })?)?;
Ok(Json(res))
}