Run 'cargo fmt' to format code (#489)
This commit is contained in:
committed by
Baptiste Gelez
parent
732f514da7
commit
b945d1f602
+45
-24
@@ -3,32 +3,42 @@ use rocket::response::Content;
|
||||
use serde_json;
|
||||
use webfinger::*;
|
||||
|
||||
use plume_models::{BASE_URL, ap_url, db_conn::DbConn, blogs::Blog, users::User};
|
||||
use plume_models::{ap_url, blogs::Blog, db_conn::DbConn, users::User, BASE_URL};
|
||||
|
||||
#[get("/.well-known/nodeinfo")]
|
||||
pub fn nodeinfo() -> Content<String> {
|
||||
Content(ContentType::new("application", "jrd+json"), json!({
|
||||
"links": [
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"href": ap_url(&format!("{domain}/nodeinfo/2.0", domain = BASE_URL.as_str()))
|
||||
},
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
||||
"href": ap_url(&format!("{domain}/nodeinfo/2.1", domain = BASE_URL.as_str()))
|
||||
}
|
||||
]
|
||||
}).to_string())
|
||||
Content(
|
||||
ContentType::new("application", "jrd+json"),
|
||||
json!({
|
||||
"links": [
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"href": ap_url(&format!("{domain}/nodeinfo/2.0", domain = BASE_URL.as_str()))
|
||||
},
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
||||
"href": ap_url(&format!("{domain}/nodeinfo/2.1", domain = BASE_URL.as_str()))
|
||||
}
|
||||
]
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/.well-known/host-meta")]
|
||||
pub fn host_meta() -> String {
|
||||
format!(r#"
|
||||
format!(
|
||||
r#"
|
||||
<?xml version="1.0"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Link rel="lrdd" type="application/xrd+xml" template="{url}"/>
|
||||
</XRD>
|
||||
"#, url = ap_url(&format!("{domain}/.well-known/webfinger?resource={{uri}}", domain = BASE_URL.as_str())))
|
||||
"#,
|
||||
url = ap_url(&format!(
|
||||
"{domain}/.well-known/webfinger?resource={{uri}}",
|
||||
domain = BASE_URL.as_str()
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
struct WebfingerResolver;
|
||||
@@ -41,20 +51,31 @@ impl Resolver<DbConn> for WebfingerResolver {
|
||||
fn find(acct: String, conn: DbConn) -> Result<Webfinger, ResolverError> {
|
||||
User::find_by_fqn(&*conn, &acct)
|
||||
.and_then(|usr| usr.webfinger(&*conn))
|
||||
.or_else(|_| Blog::find_by_fqn(&*conn, &acct)
|
||||
.and_then(|blog| blog.webfinger(&*conn))
|
||||
.or(Err(ResolverError::NotFound)))
|
||||
.or_else(|_| {
|
||||
Blog::find_by_fqn(&*conn, &acct)
|
||||
.and_then(|blog| blog.webfinger(&*conn))
|
||||
.or(Err(ResolverError::NotFound))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/.well-known/webfinger?<resource>")]
|
||||
pub fn webfinger(resource: String, conn: DbConn) -> Content<String> {
|
||||
match WebfingerResolver::endpoint(resource, conn).and_then(|wf| serde_json::to_string(&wf).map_err(|_| ResolverError::NotFound)) {
|
||||
match WebfingerResolver::endpoint(resource, conn)
|
||||
.and_then(|wf| serde_json::to_string(&wf).map_err(|_| ResolverError::NotFound))
|
||||
{
|
||||
Ok(wf) => Content(ContentType::new("application", "jrd+json"), wf),
|
||||
Err(err) => Content(ContentType::new("text", "plain"), String::from(match err {
|
||||
ResolverError::InvalidResource => "Invalid resource. Make sure to request an acct: URI",
|
||||
ResolverError::NotFound => "Requested resource was not found",
|
||||
ResolverError::WrongInstance => "This is not the instance of the requested resource"
|
||||
}))
|
||||
Err(err) => Content(
|
||||
ContentType::new("text", "plain"),
|
||||
String::from(match err {
|
||||
ResolverError::InvalidResource => {
|
||||
"Invalid resource. Make sure to request an acct: URI"
|
||||
}
|
||||
ResolverError::NotFound => "Requested resource was not found",
|
||||
ResolverError::WrongInstance => {
|
||||
"This is not the instance of the requested resource"
|
||||
}
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user