Basic blog creation
This commit is contained in:
parent
502c186f52
commit
9130f4d848
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -261,6 +261,14 @@ name = "glob"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "httparse"
|
||||
version = "1.2.4"
|
||||
@ -461,6 +469,7 @@ dependencies = [
|
||||
"bcrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dotenv 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket_codegen 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rocket_contrib 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -801,6 +810,11 @@ name = "unicode-normalization"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
@ -921,6 +935,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
|
||||
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
|
||||
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
|
||||
"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82"
|
||||
"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37"
|
||||
"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
|
||||
"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2"
|
||||
@ -988,6 +1003,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33"
|
||||
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
|
||||
"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"
|
||||
"checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum unidecode 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "402bb19d8e03f1d1a7450e2bd613980869438e0666331be3e073089124aa1adc"
|
||||
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
|
@ -5,6 +5,7 @@ version = "0.1.0"
|
||||
[dependencies]
|
||||
bcrypt = "0.2"
|
||||
dotenv = "*"
|
||||
heck = "0.3.0"
|
||||
rocket = "*"
|
||||
rocket_codegen = "*"
|
||||
|
||||
|
@ -7,6 +7,7 @@ extern crate dotenv;
|
||||
extern crate rocket;
|
||||
extern crate rocket_contrib;
|
||||
extern crate bcrypt;
|
||||
extern crate heck;
|
||||
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
@ -18,6 +19,7 @@ mod db_conn;
|
||||
mod models;
|
||||
mod schema;
|
||||
mod routes;
|
||||
mod utils;
|
||||
|
||||
use db_conn::DbConn;
|
||||
use models::instance::*;
|
||||
@ -57,7 +59,11 @@ fn main() {
|
||||
routes::user::create,
|
||||
|
||||
routes::session::new,
|
||||
routes::session::create
|
||||
routes::session::create,
|
||||
|
||||
routes::blogs::details,
|
||||
routes::blogs::new,
|
||||
routes::blogs::create,
|
||||
])
|
||||
.manage(init_pool())
|
||||
.attach(Template::fairing())
|
||||
|
42
src/routes/blogs.rs
Normal file
42
src/routes/blogs.rs
Normal file
@ -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;
|
||||
|
5
src/utils.rs
Normal file
5
src/utils.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use heck::CamelCase;
|
||||
|
||||
pub fn make_actor_id(name: String) -> String {
|
||||
name.as_str().to_camel_case()
|
||||
}
|
16
templates/blogs/new.tera
Normal file
16
templates/blogs/new.tera
Normal file
@ -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
Block a user