diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-06 19:11:26 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-06 19:11:26 -0400 |
| commit | f71975e5a89b031248d848aa553e4810178e7279 (patch) | |
| tree | f171022d7aae3ba101b05e355f49626040af45ca /src/birka-web.rs | |
| parent | 8e89d43bdf35b2a1f69f3f7e3d87c57fb1e3f58a (diff) | |
Implement tag updates.
Diffstat (limited to 'src/birka-web.rs')
| -rw-r--r-- | src/birka-web.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/birka-web.rs b/src/birka-web.rs index 22ace80..c145625 100644 --- a/src/birka-web.rs +++ b/src/birka-web.rs @@ -37,6 +37,7 @@ use multipart::{MultipartFormData, MultipartFormDataField, MultipartFormDataOpti use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use rocket::http::ContentType; +use rocket::request::Form; use rocket::{Data, State}; use rocket_contrib::json::Json; use rocket_contrib::serve::StaticFiles; @@ -145,6 +146,23 @@ fn get_post(conn: SiteState, id: i64) -> Json<ImageResult> { }) } +#[derive(FromForm)] +struct UpdateTags { + tags: String, +} + +#[post("/posts/<id>", data = "<form>")] +fn update_post(conn: SiteState, id: i64, form: Form<UpdateTags>) -> Json<String> { + let tb = &conn.inner().lock().unwrap().tb; + + for tag in form.tags.split(",") { + tb.add_tag(tag).unwrap(); + tb.tag_image(id, tag).unwrap(); + } + + Json(String::from("Updated!")) +} + #[post("/posts", data = "<data>")] fn put_post(conn: SiteState, content_type: &ContentType, data: Data) -> Json<String> { let conn = conn.inner().lock().unwrap(); @@ -246,6 +264,7 @@ fn display_posts(conn: SiteState, tags: String, last: Option<i64>) -> Template { fn display_post(conn: SiteState, id: i64) -> Template { #[derive(Serialize)] struct Context { + id: i64, tags: Vec<String>, filename: String, orig_filename: String, @@ -257,6 +276,7 @@ fn display_post(conn: SiteState, id: i64) -> Template { Template::render( "image", Context { + id, tags: tb.tags_for_image(image.id).unwrap(), filename: image_store_filename(image.id, &image.filename), orig_filename: image.filename, @@ -296,7 +316,7 @@ fn main() { .mount("/public", StaticFiles::from("./static/")) .mount("/image", StaticFiles::from(&conn.image_dir)) .mount("/", routes![index, upload, display_posts, display_post]) - .mount("/api", routes![get_posts, get_post, put_post]) + .mount("/api", routes![get_posts, get_post, put_post, update_post]) .attach(Template::fairing()) .manage(Mutex::new(conn)) .launch(); |