mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 06:41:18 +00:00
Fix review comments
This commit is contained in:
parent
8fb34843aa
commit
10da3f2554
12 changed files with 53 additions and 43 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,4 +2,3 @@ ansible/inventory
|
||||||
ansible/passwords/
|
ansible/passwords/
|
||||||
build/
|
build/
|
||||||
.idea/
|
.idea/
|
||||||
docker/dev/config/config.hjson
|
|
||||||
|
|
2
docker/dev/Dockerfile
vendored
2
docker/dev/Dockerfile
vendored
|
@ -38,7 +38,7 @@ FROM alpine:3.10
|
||||||
RUN apk add libpq
|
RUN apk add libpq
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY server/config /config
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
|
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
2
docker/dev/Dockerfile.aarch64
vendored
2
docker/dev/Dockerfile.aarch64
vendored
|
@ -69,7 +69,7 @@ RUN addgroup --gid 1000 lemmy
|
||||||
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY server/config /app/config
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/ready /app/lemmy
|
COPY --from=rust /app/server/ready /app/lemmy
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
2
docker/dev/Dockerfile.armv7hf
vendored
2
docker/dev/Dockerfile.armv7hf
vendored
|
@ -69,7 +69,7 @@ RUN addgroup --gid 1000 lemmy
|
||||||
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY server/config /config
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/ready /app/lemmy
|
COPY --from=rust /app/server/ready /app/lemmy
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
2
docker/dev/Dockerfile.libc
vendored
2
docker/dev/Dockerfile.libc
vendored
|
@ -65,7 +65,7 @@ RUN addgroup --gid 1000 lemmy
|
||||||
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY server/config /app/config
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/ready /app/lemmy
|
COPY --from=rust /app/server/ready /app/lemmy
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,8 @@ impl Community {
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_community_url(community_name: &str) -> String {
|
pub fn get_url(&self) -> String {
|
||||||
format!("https://{}/c/{}", Settings::get().hostname, community_name)
|
format!("https://{}/c/{}", Settings::get().hostname, self.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::schema::password_reset_request;
|
use crate::schema::password_reset_request;
|
||||||
use crate::schema::password_reset_request::dsl::*;
|
use crate::schema::password_reset_request::dsl::*;
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, PartialEq, Debug)]
|
#[derive(Queryable, Identifiable, PartialEq, Debug)]
|
||||||
#[table_name = "password_reset_request"]
|
#[table_name = "password_reset_request"]
|
||||||
|
|
|
@ -151,8 +151,8 @@ impl User_ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_user_profile_url(username: &str) -> String {
|
pub fn get_profile_url(&self) -> String {
|
||||||
format!("https://{}/u/{}", Settings::get().hostname, username)
|
format!("https://{}/u/{}", Settings::get().hostname, self.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_jwt(conn: &PgConnection, jwt: &str) -> Result<Self, Error> {
|
pub fn find_by_jwt(conn: &PgConnection, jwt: &str) -> Result<Self, Error> {
|
||||||
|
|
|
@ -111,7 +111,7 @@ fn get_feed_user(sort_type: &SortType, user_name: String) -> Result<String, Erro
|
||||||
|
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(&conn)?;
|
||||||
let user = User_::find_by_username(&conn, &user_name)?;
|
let user = User_::find_by_username(&conn, &user_name)?;
|
||||||
let user_url = User_::get_user_profile_url(&user_name);
|
let user_url = user.get_profile_url();
|
||||||
|
|
||||||
let posts = PostQueryBuilder::create(&conn)
|
let posts = PostQueryBuilder::create(&conn)
|
||||||
.listing_type(ListingType::All)
|
.listing_type(ListingType::All)
|
||||||
|
@ -135,7 +135,7 @@ fn get_feed_community(sort_type: &SortType, community_name: String) -> Result<St
|
||||||
|
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(&conn)?;
|
||||||
let community = Community::read_from_name(&conn, community_name)?;
|
let community = Community::read_from_name(&conn, community_name)?;
|
||||||
let community_url = Community::get_community_url(&community.name);
|
let community_url = community.get_url();
|
||||||
|
|
||||||
let posts = PostQueryBuilder::create(&conn)
|
let posts = PostQueryBuilder::create(&conn)
|
||||||
.listing_type(ListingType::All)
|
.listing_type(ListingType::All)
|
||||||
|
|
|
@ -11,7 +11,6 @@ pub extern crate actix;
|
||||||
pub extern crate actix_web;
|
pub extern crate actix_web;
|
||||||
pub extern crate bcrypt;
|
pub extern crate bcrypt;
|
||||||
pub extern crate chrono;
|
pub extern crate chrono;
|
||||||
pub extern crate sha2;
|
|
||||||
pub extern crate dotenv;
|
pub extern crate dotenv;
|
||||||
pub extern crate jsonwebtoken;
|
pub extern crate jsonwebtoken;
|
||||||
pub extern crate lettre;
|
pub extern crate lettre;
|
||||||
|
@ -20,6 +19,7 @@ pub extern crate rand;
|
||||||
pub extern crate regex;
|
pub extern crate regex;
|
||||||
pub extern crate serde;
|
pub extern crate serde;
|
||||||
pub extern crate serde_json;
|
pub extern crate serde_json;
|
||||||
|
pub extern crate sha2;
|
||||||
pub extern crate strum;
|
pub extern crate strum;
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::Settings;
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
use actix_web::web::Query;
|
use actix_web::web::Query;
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -12,6 +13,14 @@ pub struct Params {
|
||||||
resource: String,
|
resource: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
|
||||||
|
"^group:([a-z0-9_]{{3, 20}})@{}$",
|
||||||
|
Settings::get().hostname
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
/// Responds to webfinger requests of the following format. There isn't any real documentation for
|
/// Responds to webfinger requests of the following format. There isn't any real documentation for
|
||||||
/// this, but it described in this blog post:
|
/// this, but it described in this blog post:
|
||||||
/// https://mastodon.social/.well-known/webfinger?resource=acct:gargron@mastodon.social
|
/// https://mastodon.social/.well-known/webfinger?resource=acct:gargron@mastodon.social
|
||||||
|
@ -19,26 +28,27 @@ pub struct Params {
|
||||||
/// You can also view the webfinger response that Mastodon sends:
|
/// You can also view the webfinger response that Mastodon sends:
|
||||||
/// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
|
/// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
|
||||||
pub fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
|
pub fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
|
||||||
// NOTE: Calling the parameter "account" maybe doesn't really make sense, but should give us the
|
let regex_parsed = WEBFINGER_COMMUNITY_REGEX
|
||||||
// best compatibility with existing implementations. We could also support an alternative name
|
.captures(&info.resource)
|
||||||
// like "group", and encourage others to use that.
|
.map(|c| c.get(1));
|
||||||
let community_identifier = info.resource.replace("acct:", "");
|
// TODO: replace this with .flatten() once we are running rust 1.40
|
||||||
let split_identifier: Vec<&str> = community_identifier.split("@").collect();
|
let regex_parsed_flattened = match regex_parsed {
|
||||||
let community_name = split_identifier[0];
|
Some(s) => s,
|
||||||
// It looks like Mastodon does not return webfinger requests for users from other instances, so we
|
None => None,
|
||||||
// don't do that either.
|
};
|
||||||
if split_identifier.len() != 2 || split_identifier[1] != Settings::get().hostname {
|
let community_name = match regex_parsed_flattened {
|
||||||
return HttpResponse::NotFound().finish();
|
Some(c) => c.as_str(),
|
||||||
}
|
None => return HttpResponse::NotFound().finish(),
|
||||||
|
};
|
||||||
|
|
||||||
// Make sure the requested community exists.
|
// Make sure the requested community exists.
|
||||||
let conn = establish_connection();
|
let conn = establish_connection();
|
||||||
match Community::read_from_name(&conn, community_name.to_owned()) {
|
let community = match Community::read_from_name(&conn, community_name.to_string()) {
|
||||||
|
Ok(o) => o,
|
||||||
Err(_) => return HttpResponse::NotFound().finish(),
|
Err(_) => return HttpResponse::NotFound().finish(),
|
||||||
Ok(c) => c,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_url = Community::get_community_url(&community_name);
|
let community_url = community.get_url();
|
||||||
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
"subject": info.resource,
|
"subject": info.resource,
|
||||||
|
@ -54,7 +64,8 @@ pub fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
|
||||||
{
|
{
|
||||||
"rel": "self",
|
"rel": "self",
|
||||||
"type": "application/activity+json",
|
"type": "application/activity+json",
|
||||||
"href": community_url // Yes this is correct, this link doesn't include the `.json` extension
|
// Yes this is correct, this link doesn't include the `.json` extension
|
||||||
|
"href": community_url
|
||||||
}
|
}
|
||||||
// TODO: this also needs to return the subscribe link once that's implemented
|
// TODO: this also needs to return the subscribe link once that's implemented
|
||||||
//{
|
//{
|
||||||
|
@ -63,7 +74,7 @@ pub fn get_webfinger_response(info: Query<Params>) -> HttpResponse<Body> {
|
||||||
//}
|
//}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
return HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("application/activity+json")
|
.content_type("application/activity+json")
|
||||||
.body(json.to_string());
|
.body(json.to_string())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue