Basic blog creation
parent
502c186f52
commit
9130f4d848
@ -0,0 +1,42 @@
|
||||
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())
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod blogs;
|
||||
pub mod instance;
|
||||
pub mod session;
|
||||
pub mod user;
|
||||
|
@ -0,0 +1,5 @@
|
||||
use heck::CamelCase;
|
||||
|
||||
pub fn make_actor_id(name: String) -> String {
|
||||
name.as_str().to_camel_case()
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>New blog</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Create a blog</h1>
|
||||
<form method="post">
|
||||
<label for="title">Title</label>
|
||||
<input name="title">
|
||||
|
||||
<input type="submit" value="Create blog"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue