wip: api router

This commit is contained in:
saji 2024-07-24 09:43:09 -05:00
parent b5073bec89
commit a00e0dd08d
5 changed files with 26 additions and 5 deletions

9
Cargo.lock generated
View file

@ -1358,6 +1358,7 @@ dependencies = [
"palette",
"rayon",
"rgb",
"thiserror",
"tokio",
]
@ -1852,18 +1853,18 @@ checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2"
[[package]]
name = "thiserror"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [
"proc-macro2",
"quote",

View file

@ -20,4 +20,5 @@ num-traits = "0.2.19"
palette = "0.7.6"
rayon = "1.10.0"
rgb = "0.8.40"
thiserror = "1.0.63"
tokio = { version = "1.38.1", features = ["full"] }

View file

@ -1,7 +1,21 @@
use axum::{Router};
use axum::{extract::State, http::StatusCode, routing::post, Router};
use crate::display::Wrapper;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
struct ApiContext {
display: Arc<Mutex<Wrapper>>,
}
/// API routes for axum
/// Start with the basics: Send an image, crop it, dither, and upload.
/// we defer the upload to a separate task.
pub fn router() -> Router<ApiContext> {
Router::new()
.route("/setimage", post(set_image))
}
async fn set_image(State(ctx): State<ApiContext>) {
}

1
src/errors.rs Normal file
View file

@ -0,0 +1 @@
use thiserror;

View file

@ -2,6 +2,7 @@
pub mod display;
pub mod imageproc;
pub mod api;
pub mod errors;
use crate::display::Wrapper;
use crate::imageproc::{DiffusionMatrix, Ditherer, EInkImage, ErrorDiffusionDither};
@ -48,5 +49,8 @@ async fn main() -> anyhow::Result<()> {
display.test()?;
}
if matches!(cli.command, Command::Serve) {
}
Ok(())
}