Merge branch 'main' of https://github.com/lemmynet/lemmy into main
This commit is contained in:
commit
ceb18b528a
5 changed files with 59 additions and 17 deletions
|
@ -133,10 +133,7 @@ impl Community {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn community_mods_and_admins(
|
fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
|
||||||
conn: &PgConnection,
|
|
||||||
community_id: i32,
|
|
||||||
) -> Result<Vec<i32>, Error> {
|
|
||||||
use crate::{community_view::CommunityModeratorView, user_view::UserView};
|
use crate::{community_view::CommunityModeratorView, user_view::UserView};
|
||||||
let mut mods_and_admins: Vec<i32> = Vec::new();
|
let mut mods_and_admins: Vec<i32> = Vec::new();
|
||||||
mods_and_admins.append(
|
mods_and_admins.append(
|
||||||
|
|
|
@ -33,7 +33,7 @@ use lemmy_db::{
|
||||||
user::User_,
|
user::User_,
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{convert_datetime, get_apub_protocol_string, settings::Settings};
|
use lemmy_utils::convert_datetime;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -114,15 +114,8 @@ impl ToApub for Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(thumbnail_url) = &self.thumbnail_url {
|
if let Some(thumbnail_url) = &self.thumbnail_url {
|
||||||
let full_url = format!(
|
|
||||||
"{}://{}/pictshare/{}",
|
|
||||||
get_apub_protocol_string(),
|
|
||||||
Settings::get().hostname,
|
|
||||||
thumbnail_url
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut image = Image::new();
|
let mut image = Image::new();
|
||||||
image.set_url(full_url);
|
image.set_url(thumbnail_url.to_string());
|
||||||
page.set_image(image.into_any_base()?);
|
page.set_image(image.into_any_base()?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// This is for db migrations that require code
|
// This is for db migrations that require code
|
||||||
use crate::LemmyError;
|
use crate::LemmyError;
|
||||||
use diesel::*;
|
use diesel::{
|
||||||
|
sql_types::{Nullable, Text},
|
||||||
|
*,
|
||||||
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
|
@ -10,7 +13,13 @@ use lemmy_db::{
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{generate_actor_keypair, make_apub_endpoint, EndpointType};
|
use lemmy_utils::{
|
||||||
|
generate_actor_keypair,
|
||||||
|
get_apub_protocol_string,
|
||||||
|
make_apub_endpoint,
|
||||||
|
settings::Settings,
|
||||||
|
EndpointType,
|
||||||
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
|
pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
|
@ -19,6 +28,7 @@ pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
post_updates_2020_04_03(&conn)?;
|
post_updates_2020_04_03(&conn)?;
|
||||||
comment_updates_2020_04_03(&conn)?;
|
comment_updates_2020_04_03(&conn)?;
|
||||||
private_message_updates_2020_05_05(&conn)?;
|
private_message_updates_2020_05_05(&conn)?;
|
||||||
|
post_thumbnail_url_updates_2020_07_27(&conn)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -188,3 +198,32 @@ fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyEr
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn post_thumbnail_url_updates_2020_07_27(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
|
use lemmy_db::schema::post::dsl::*;
|
||||||
|
|
||||||
|
info!("Running post_thumbnail_url_updates_2020_07_27");
|
||||||
|
|
||||||
|
let domain_prefix = format!(
|
||||||
|
"{}://{}/pictrs/image/",
|
||||||
|
get_apub_protocol_string(),
|
||||||
|
Settings::get().hostname
|
||||||
|
);
|
||||||
|
|
||||||
|
let incorrect_thumbnails = post.filter(thumbnail_url.not_like("http%"));
|
||||||
|
|
||||||
|
// Prepend the rows with the update
|
||||||
|
let res = diesel::update(incorrect_thumbnails)
|
||||||
|
.set(
|
||||||
|
thumbnail_url.eq(
|
||||||
|
domain_prefix
|
||||||
|
.into_sql::<Nullable<Text>>()
|
||||||
|
.concat(thumbnail_url),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get_results::<Post>(conn)?;
|
||||||
|
|
||||||
|
info!("{} Post thumbnail_url rows updated.", res.len());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ pub mod websocket;
|
||||||
|
|
||||||
use crate::request::{retry, RecvError};
|
use crate::request::{retry, RecvError};
|
||||||
use actix_web::{client::Client, dev::ConnectionInfo};
|
use actix_web::{client::Client, dev::ConnectionInfo};
|
||||||
|
use lemmy_utils::{get_apub_protocol_string, settings::Settings};
|
||||||
use log::error;
|
use log::error;
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -140,7 +141,7 @@ async fn fetch_iframely_and_pictrs_data(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch pictrs thumbnail
|
// Fetch pictrs thumbnail
|
||||||
let pictrs_thumbnail = match iframely_thumbnail_url {
|
let pictrs_hash = match iframely_thumbnail_url {
|
||||||
Some(iframely_thumbnail_url) => match fetch_pictrs(client, &iframely_thumbnail_url).await {
|
Some(iframely_thumbnail_url) => match fetch_pictrs(client, &iframely_thumbnail_url).await {
|
||||||
Ok(res) => Some(res.files[0].file.to_owned()),
|
Ok(res) => Some(res.files[0].file.to_owned()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -158,6 +159,18 @@ async fn fetch_iframely_and_pictrs_data(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The full urls are necessary for federation
|
||||||
|
let pictrs_thumbnail = if let Some(pictrs_hash) = pictrs_hash {
|
||||||
|
Some(format!(
|
||||||
|
"{}://{}/pictrs/image/{}",
|
||||||
|
get_apub_protocol_string(),
|
||||||
|
Settings::get().hostname,
|
||||||
|
pictrs_hash
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
iframely_title,
|
iframely_title,
|
||||||
iframely_description,
|
iframely_description,
|
||||||
|
|
2
ui/package.json
vendored
2
ui/package.json
vendored
|
@ -82,7 +82,7 @@
|
||||||
"eslint --fix"
|
"eslint --fix"
|
||||||
],
|
],
|
||||||
"../server/src/**/*.rs": [
|
"../server/src/**/*.rs": [
|
||||||
"rustfmt --config-path ../server/.rustfmt.toml"
|
"rustfmt +nightly --config-path ../server/.rustfmt.toml"
|
||||||
],
|
],
|
||||||
"package.json": [
|
"package.json": [
|
||||||
"sortpack"
|
"sortpack"
|
||||||
|
|
Loading…
Reference in a new issue