Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap out iframely #1706

Merged
merged 11 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
531 changes: 428 additions & 103 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Each Lemmy server can set its own moderation policy; appointing site-wide admins
- Can transfer site and communities to others.
- Can fully erase your data, replacing all posts and comments.
- NSFW post / community support.
- OEmbed support via Iframely.
- High performance.
- Server is written in rust.
- Front end is `~80kB` gzipped.
Expand Down
4 changes: 0 additions & 4 deletions ansible/lemmy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@
- src: 'templates/nginx.conf'
dest: '/etc/nginx/sites-enabled/lemmy.conf'
mode: '0644'
- src: '../docker/iframely.config.local.js'
dest: '{{lemmy_base_dir}}/iframely.config.local.js'
mode: '0600'
vars:
lemmy_docker_image: "dessalines/lemmy:{{ lookup('file', 'VERSION') }}"
lemmy_docker_ui_image: "dessalines/lemmy-ui:{{ lookup('file', 'VERSION') }}"
lemmy_port: "8536"
lemmy_ui_port: "1235"
pictshare_port: "8537"
iframely_port: "8538"

- name: add config file (only during initial setup)
template:
Expand Down
4 changes: 0 additions & 4 deletions ansible/lemmy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@
- src: 'templates/nginx.conf'
dest: '/etc/nginx/sites-enabled/lemmy.conf'
mode: '0644'
- src: '../docker/iframely.config.local.js'
dest: '{{lemmy_base_dir}}/iframely.config.local.js'
mode: '0600'
vars:
lemmy_docker_image: "dessalines/lemmy:dev"
lemmy_docker_ui_image: "dessalines/lemmy-ui:{{ lookup('file', 'VERSION') }}"
lemmy_port: "8536"
lemmy_ui_port: "1235"
pictshare_port: "8537"
iframely_port: "8538"
postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"

- name: add config file (only during initial setup)
Expand Down
10 changes: 0 additions & 10 deletions ansible/templates/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:
depends_on:
- postgres
- pictrs
- iframely

lemmy-ui:
image: {{ lemmy_docker_ui_image }}
Expand Down Expand Up @@ -47,15 +46,6 @@ services:
restart: always
mem_limit: 200m

iframely:
image: dogbin/iframely:latest
ports:
- "127.0.0.1:8061:80"
volumes:
- ./iframely.config.local.js:/iframely/config.local.js:ro
restart: always
mem_limit: 200m

postfix:
image: mwader/postfix-relay
environment:
Expand Down
6 changes: 0 additions & 6 deletions ansible/templates/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ server {
return 301 /pictrs/image/$1;
}

location /iframely/ {
proxy_pass http://0.0.0.0:8061/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

# Anonymize IP addresses
Expand Down
2 changes: 0 additions & 2 deletions config/config.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
jwt_secret: "changeme"
# address where pictrs is available
pictrs_url: "http://pictrs:8080"
# address where iframely is available
iframely_url: "http://iframely"
# maximum length of local community and user names
actor_name_max_length: 20
# rate limits for various user actions, by user ip
Expand Down
3 changes: 3 additions & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pub async fn match_websocket_operation(
UserOperation::ResolvePostReport => {
do_websocket_operation::<ResolvePostReport>(context, id, op, data).await
}
UserOperation::GetSiteMetadata => {
do_websocket_operation::<GetSiteMetadata>(context, id, op, data).await
}

// Comment ops
UserOperation::MarkCommentAsRead => {
Expand Down
19 changes: 18 additions & 1 deletion crates/api/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use lemmy_apub::{
use lemmy_db_queries::{source::post::Post_, Crud, Likeable, Saveable};
use lemmy_db_schema::source::{moderator::*, post::*};
use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_utils::{request::fetch_site_metadata, ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
use std::convert::TryInto;

Expand Down Expand Up @@ -285,3 +285,20 @@ impl Perform for SavePost {
Ok(PostResponse { post_view })
}
}

#[async_trait::async_trait(?Send)]
impl Perform for GetSiteMetadata {
type Response = GetSiteMetadataResponse;

async fn perform(
&self,
context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<GetSiteMetadataResponse, LemmyError> {
let data: &Self = self;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you rename self in every API method? For me its quite confusing, because it doesnt actually do anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just history, these used to be very different impls. If someone wanted to go through and change all these to self, it wouldn't hurt anything, but data to me is more clear as its describing that its the Form data.


let metadata = fetch_site_metadata(context.client(), &data.url).await?;

Ok(GetSiteMetadataResponse { metadata })
}
}
11 changes: 11 additions & 0 deletions crates/api_common/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use lemmy_db_views_actor::{
community_moderator_view::CommunityModeratorView,
community_view::CommunityView,
};
use lemmy_utils::request::SiteMetadata;
use serde::{Deserialize, Serialize};
use url::Url;

Expand Down Expand Up @@ -148,3 +149,13 @@ pub struct ListPostReports {
pub struct ListPostReportsResponse {
pub posts: Vec<PostReportView>,
}

#[derive(Deserialize, Debug)]
pub struct GetSiteMetadata {
pub url: Url,
}

#[derive(Serialize, Clone, Debug)]
pub struct GetSiteMetadataResponse {
pub metadata: SiteMetadata,
}
9 changes: 4 additions & 5 deletions crates/api_crud/src/post/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use lemmy_apub::{
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
use lemmy_db_schema::source::post::*;
use lemmy_utils::{
request::fetch_iframely_and_pictrs_data,
request::fetch_site_data,
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
ApiError,
ConnectionId,
Expand Down Expand Up @@ -49,11 +49,10 @@ impl PerformCrud for CreatePost {

check_community_ban(local_user_view.person.id, data.community_id, context.pool()).await?;

// Fetch Iframely and pictrs cached image
// Fetch post links and pictrs cached image
let data_url = data.url.as_ref();
let (iframely_response, pictrs_thumbnail) =
fetch_iframely_and_pictrs_data(context.client(), data_url).await?;
let (embed_title, embed_description, embed_html) = iframely_response
let (metadata_res, pictrs_thumbnail) = fetch_site_data(context.client(), data_url).await;
let (embed_title, embed_description, embed_html) = metadata_res
.map(|u| (u.title, u.description, u.html))
.unwrap_or((None, None, None));

Expand Down
9 changes: 4 additions & 5 deletions crates/api_crud/src/post/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateO
use lemmy_db_queries::{source::post::Post_, Crud};
use lemmy_db_schema::{naive_now, source::post::*};
use lemmy_utils::{
request::fetch_iframely_and_pictrs_data,
request::fetch_site_data,
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
ApiError,
ConnectionId,
Expand Down Expand Up @@ -49,11 +49,10 @@ impl PerformCrud for EditPost {
return Err(ApiError::err("no_post_edit_allowed").into());
}

// Fetch Iframely and Pictrs cached image
// Fetch post links and Pictrs cached image
let data_url = data.url.as_ref();
let (iframely_response, pictrs_thumbnail) =
fetch_iframely_and_pictrs_data(context.client(), data_url).await?;
let (embed_title, embed_description, embed_html) = iframely_response
let (metadata_res, pictrs_thumbnail) = fetch_site_data(context.client(), data_url).await;
let (embed_title, embed_description, embed_html) = metadata_res
.map(|u| (u.title, u.description, u.html))
.unwrap_or((None, None, None));

Expand Down
8 changes: 4 additions & 4 deletions crates/apub/src/objects/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use lemmy_db_schema::{
},
};
use lemmy_utils::{
request::fetch_iframely_and_pictrs_data,
request::fetch_site_data,
utils::{check_slurs, convert_datetime, markdown_to_html, remove_slurs},
LemmyError,
};
Expand Down Expand Up @@ -188,12 +188,12 @@ impl FromApub for Post {
let community = extract_community(&page.to, context, request_counter).await?;

let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
let (iframely_response, pictrs_thumbnail) = if let Some(url) = &page.url {
fetch_iframely_and_pictrs_data(context.client(), Some(url)).await?
let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.url {
fetch_site_data(context.client(), Some(url)).await
} else {
(None, thumbnail_url)
};
let (embed_title, embed_description, embed_html) = iframely_response
let (embed_title, embed_description, embed_html) = metadata_res
.map(|u| (u.title, u.description, u.html))
.unwrap_or((None, None, None));

Expand Down
1 change: 1 addition & 0 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ http = "0.2.4"
jsonwebtoken = "7.2.0"
deser-hjson = "1.0.2"
smart-default = "0.6.0"
webpage = { version = "1.1", default-features = false, features = ["serde"] }
Loading