implement Host more completely by doing less
we now use DieselNewType and Shrinkwrap to automatically derive all the things we need.
This commit is contained in:
parent
92bbeeb45e
commit
65ae51b7e5
@ -25,30 +25,17 @@ use posts::Post;
|
|||||||
use safe_string::SafeString;
|
use safe_string::SafeString;
|
||||||
use schema::blogs;
|
use schema::blogs;
|
||||||
use search::Searcher;
|
use search::Searcher;
|
||||||
use std::fmt;
|
|
||||||
use users::User;
|
use users::User;
|
||||||
use {Connection, Error, PlumeRocket, Result};
|
use {Connection, Error, PlumeRocket, Result};
|
||||||
|
|
||||||
pub type CustomGroup = CustomObject<ApSignature, Group>;
|
pub type CustomGroup = CustomObject<ApSignature, Group>;
|
||||||
|
|
||||||
#[derive(Queryable, Clone)]
|
#[derive(Clone, Debug, DieselNewType, Shrinkwrap)]
|
||||||
pub struct Host(String);
|
pub struct Host(String);
|
||||||
|
|
||||||
impl Host {
|
impl Host {
|
||||||
pub fn new<T: Into<String>>(host: T) -> Host {
|
pub fn new(host: impl ToString) -> Host {
|
||||||
Host(host.into())
|
Host(host.to_string())
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<String> for Host {
|
|
||||||
fn into(self) -> String {
|
|
||||||
self.0.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<String> for Host {
|
|
||||||
fn from(s: String) -> Host {
|
|
||||||
Host::new(s)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,12 +45,6 @@ impl AsRef<str> for Host {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Host {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
pub struct Blog {
|
pub struct Blog {
|
||||||
@ -82,7 +63,7 @@ pub struct Blog {
|
|||||||
pub summary_html: SafeString,
|
pub summary_html: SafeString,
|
||||||
pub icon_id: Option<i32>,
|
pub icon_id: Option<i32>,
|
||||||
pub banner_id: Option<i32>,
|
pub banner_id: Option<i32>,
|
||||||
pub custom_domain: Option<String>,
|
pub custom_domain: Option<Host>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Insertable)]
|
#[derive(Default, Insertable)]
|
||||||
@ -341,7 +322,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Host {
|
|||||||
.get_one("Host")
|
.get_one("Host")
|
||||||
.and_then(|x| {
|
.and_then(|x| {
|
||||||
if x != Instance::get_local().ok()?.public_domain {
|
if x != Instance::get_local().ok()?.public_domain {
|
||||||
Some(Host(x.to_string()))
|
Some(Host::new(x))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ extern crate bcrypt;
|
|||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel_derive_newtype;
|
||||||
extern crate guid_create;
|
extern crate guid_create;
|
||||||
extern crate heck;
|
extern crate heck;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
@ -31,6 +33,8 @@ extern crate serde_derive;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
extern crate shrinkwraprs;
|
||||||
|
#[macro_use]
|
||||||
extern crate tantivy;
|
extern crate tantivy;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate webfinger;
|
extern crate webfinger;
|
||||||
|
Loading…
Reference in New Issue
Block a user