mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-14 07:51:01 +00:00
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
|
use rocket::request::Form;
|
||
|
use rocket::response::Redirect;
|
||
|
use rocket_contrib::Template;
|
||
|
use std::collections::HashMap;
|
||
|
|
||
|
use utils;
|
||
|
use db_conn::DbConn;
|
||
|
use models::blogs::*;
|
||
|
use models::instance::Instance;
|
||
|
|
||
|
#[get("/~/<name>")]
|
||
|
fn details(name: String) -> String {
|
||
|
format!("Welcome on ~{}", name)
|
||
|
}
|
||
|
|
||
|
#[get("/blogs/new")]
|
||
|
fn new() -> Template {
|
||
|
Template::render("blogs/new", HashMap::<String, i32>::new())
|
||
|
}
|
||
|
|
||
|
#[derive(FromForm)]
|
||
|
struct NewBlogForm {
|
||
|
pub title: String
|
||
|
}
|
||
|
|
||
|
#[post("/blogs/new", data = "<data>")]
|
||
|
fn create(conn: DbConn, data: Form<NewBlogForm>) -> Redirect {
|
||
|
let inst = Instance::get_local(&*conn).unwrap();
|
||
|
let form = data.get();
|
||
|
let slug = utils::make_actor_id(form.title.to_string());
|
||
|
|
||
|
Blog::insert(&*conn, NewBlog {
|
||
|
actor_id: slug.to_string(),
|
||
|
title: form.title.to_string(),
|
||
|
summary: String::from(""),
|
||
|
outbox_url: Blog::compute_outbox(slug.to_string(), inst.public_domain.to_string()),
|
||
|
inbox_url: Blog::compute_inbox(slug.to_string(), inst.public_domain.to_string()),
|
||
|
instance_id: inst.id
|
||
|
});
|
||
|
|
||
|
Redirect::to(format!("/~/{}", slug).as_str())
|
||
|
}
|