add: drawings in questions
This commit is contained in:
parent
6be729de50
commit
16843a6ab8
28 changed files with 1181 additions and 32 deletions
|
@ -15,6 +15,7 @@ use tetratto_core::model::{
|
|||
};
|
||||
use crate::{
|
||||
get_user_from_token,
|
||||
image::JsonMultipart,
|
||||
routes::{api::v1::CreateQuestion, pages::PaginatedQuery},
|
||||
State,
|
||||
};
|
||||
|
@ -23,7 +24,7 @@ pub async fn create_request(
|
|||
jar: CookieJar,
|
||||
headers: HeaderMap,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<CreateQuestion>,
|
||||
JsonMultipart(drawings, req): JsonMultipart<CreateQuestion>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = get_user_from_token!(jar, data, oauth::AppScope::UserCreateQuestions);
|
||||
|
@ -70,7 +71,10 @@ pub async fn create_request(
|
|||
}
|
||||
}
|
||||
|
||||
match data.create_question(props).await {
|
||||
match data
|
||||
.create_question(props, drawings.iter().map(|x| x.to_vec()).collect())
|
||||
.await
|
||||
{
|
||||
Ok(id) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Question created".to_string(),
|
||||
|
|
|
@ -57,10 +57,18 @@ pub async fn get_css_request(
|
|||
|
||||
let note = match data.get_note_by_journal_title(id, "journal.css").await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return ([("Content-Type", "text/plain")], format!("/* {e} */")),
|
||||
Err(e) => {
|
||||
return (
|
||||
[("Content-Type", "text/css"), ("Cache-Control", "no-cache")],
|
||||
format!("/* {e} */"),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
([("Content-Type", "text/css")], note.content)
|
||||
(
|
||||
[("Content-Type", "text/css"), ("Cache-Control", "no-cache")],
|
||||
note.content,
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn list_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
|
|
|
@ -4,7 +4,7 @@ use axum_extra::extract::CookieJar;
|
|||
use pathbufd::PathBufD;
|
||||
use crate::{get_user_from_token, State};
|
||||
use super::auth::images::read_image;
|
||||
use tetratto_core::model::{oauth, ApiReturn, Error};
|
||||
use tetratto_core::model::{carp::CarpGraph, oauth, uploads::MediaType, ApiReturn, Error};
|
||||
|
||||
pub async fn get_request(
|
||||
Path(id): Path<usize>,
|
||||
|
@ -39,10 +39,17 @@ pub async fn get_request(
|
|||
));
|
||||
}
|
||||
|
||||
Ok((
|
||||
[("Content-Type", upload.what.mime())],
|
||||
Body::from(read_image(path)),
|
||||
))
|
||||
let bytes = read_image(path);
|
||||
|
||||
if upload.what == MediaType::Carpgraph {
|
||||
// conver to svg and return
|
||||
return Ok((
|
||||
[("Content-Type", "image/svg+xml".to_string())],
|
||||
Body::from(CarpGraph::from_bytes(bytes).to_svg()),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(([("Content-Type", upload.what.mime())], Body::from(bytes)))
|
||||
}
|
||||
|
||||
pub async fn delete_request(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue