Add support for inline images

This commit is contained in:
2024-07-05 10:38:12 -07:00
parent 55d7aec516
commit 3a5a9bd66a
4 changed files with 119 additions and 33 deletions

View File

@@ -16,7 +16,9 @@ use rocket::{
use rocket_cors::{AllowedHeaders, AllowedOrigins};
use server::{
error::ServerError,
graphql::{attachment_bytes, Attachment, GraphqlSchema, Mutation, QueryRoot},
graphql::{
attachment_bytes, cid_attachment_bytes, Attachment, GraphqlSchema, Mutation, QueryRoot,
},
};
#[get("/refresh")]
@@ -111,6 +113,22 @@ impl<'r, 'o: 'r> Responder<'r, 'o> for DownloadAttachmentResponder {
}
}
#[get("/cid/<id>/<cid>")]
async fn view_cid(
nm: &State<Notmuch>,
id: &str,
cid: &str,
) -> Result<InlineAttachmentResponder, Debug<ServerError>> {
let mid = if id.starts_with("id:") {
id.to_string()
} else {
format!("id:{}", id)
};
info!("view cid attachment {mid} {cid}");
let attachment = cid_attachment_bytes(nm, &mid, &cid)?;
Ok(InlineAttachmentResponder(attachment))
}
#[get("/view/attachment/<id>/<idx>/<_>")]
async fn view_attachment(
nm: &State<Notmuch>,
@@ -224,6 +242,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
graphql_query,
graphql_request,
graphiql,
view_cid,
view_attachment,
download_attachment,
],