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 schema::blogs; | ||||
| use search::Searcher; | ||||
| use std::fmt; | ||||
| use users::User; | ||||
| use {Connection, Error, PlumeRocket, Result}; | ||||
| 
 | ||||
| pub type CustomGroup = CustomObject<ApSignature, Group>; | ||||
| 
 | ||||
| #[derive(Queryable, Clone)] | ||||
| #[derive(Clone, Debug, DieselNewType, Shrinkwrap)] | ||||
| pub struct Host(String); | ||||
| 
 | ||||
| impl Host { | ||||
|     pub fn new<T: Into<String>>(host: T) -> Host { | ||||
|         Host(host.into()) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 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) | ||||
|     pub fn new(host: impl ToString) -> Host { | ||||
|         Host(host.to_string()) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -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)] | ||||
| #[changeset_options(treat_none_as_null = "true")] | ||||
| pub struct Blog { | ||||
| @ -82,7 +63,7 @@ pub struct Blog { | ||||
|     pub summary_html: SafeString, | ||||
|     pub icon_id: Option<i32>, | ||||
|     pub banner_id: Option<i32>, | ||||
|     pub custom_domain: Option<String>, | ||||
|     pub custom_domain: Option<Host>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Default, Insertable)] | ||||
| @ -341,7 +322,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Host { | ||||
|             .get_one("Host") | ||||
|             .and_then(|x| { | ||||
|                 if x != Instance::get_local().ok()?.public_domain { | ||||
|                     Some(Host(x.to_string())) | ||||
|                     Some(Host::new(x)) | ||||
|                 } else { | ||||
|                     None | ||||
|                 } | ||||
|  | ||||
| @ -10,6 +10,8 @@ extern crate bcrypt; | ||||
| extern crate chrono; | ||||
| #[macro_use] | ||||
| extern crate diesel; | ||||
| #[macro_use] | ||||
| extern crate diesel_derive_newtype; | ||||
| extern crate guid_create; | ||||
| extern crate heck; | ||||
| extern crate itertools; | ||||
| @ -31,6 +33,8 @@ extern crate serde_derive; | ||||
| #[macro_use] | ||||
| extern crate serde_json; | ||||
| #[macro_use] | ||||
| extern crate shrinkwraprs; | ||||
| #[macro_use] | ||||
| extern crate tantivy; | ||||
| extern crate url; | ||||
| extern crate webfinger; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user