summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9a458d2)
* Use og:video attribute for embeds, change Post.embed_html to embed_url
* fix clippy
12 files changed:
use crate::sensitive::Sensitive;
use lemmy_db_schema::{
use crate::sensitive::Sensitive;
use lemmy_db_schema::{
- newtypes::{CommunityId, PostId, PostReportId},
+ newtypes::{CommunityId, DbUrl, PostId, PostReportId},
ListingType,
SortType,
};
ListingType,
SortType,
};
pub struct SiteMetadata {
pub title: Option<String>,
pub description: Option<String>,
pub struct SiteMetadata {
pub title: Option<String>,
pub description: Option<String>,
- pub(crate) image: Option<Url>,
- pub html: Option<String>,
+ pub(crate) image: Option<DbUrl>,
+ pub embed_video_url: Option<DbUrl>,
use crate::post::SiteMetadata;
use encoding::{all::encodings, DecoderTrap};
use crate::post::SiteMetadata;
use encoding::{all::encodings, DecoderTrap};
+use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::{error::LemmyError, settings::structs::Settings, version::VERSION};
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use reqwest_middleware::ClientWithMiddleware;
use lemmy_utils::{error::LemmyError, settings::structs::Settings, version::VERSION};
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use reqwest_middleware::ClientWithMiddleware;
.images
.get(0)
.and_then(|ogo| Url::parse(&ogo.url).ok());
.images
.get(0)
.and_then(|ogo| Url::parse(&ogo.url).ok());
-
- let title = og_title.or(page_title);
- let description = og_description.or(page_description);
- let image = og_image;
+ let og_embed_url = page
+ .opengraph
+ .videos
+ .first()
+ .and_then(|v| Url::parse(&v.url).ok());
- title,
- description,
- image,
- html: None,
+ title: og_title.or(page_title),
+ description: og_description.or(page_description),
+ image: og_image.map(Into::into),
+ embed_video_url: og_embed_url.map(Into::into),
client: &ClientWithMiddleware,
settings: &Settings,
url: Option<&Url>,
client: &ClientWithMiddleware,
settings: &Settings,
url: Option<&Url>,
-) -> (Option<SiteMetadata>, Option<Url>) {
+) -> (Option<SiteMetadata>, Option<DbUrl>) {
match &url {
Some(url) => {
// Fetch metadata
match &url {
Some(url) => {
// Fetch metadata
- (metadata_option, pictrs_thumbnail)
+ (metadata_option, pictrs_thumbnail.map(Into::into))
}
None => (None, None),
}
}
None => (None, None),
}
image: Some(
Url::parse("https://gitlab.com/uploads/-/system/project/avatar/4877469/iod_logo.png")
.unwrap()
image: Some(
Url::parse("https://gitlab.com/uploads/-/system/project/avatar/4877469/iod_logo.png")
.unwrap()
// Fetch post links and pictrs cached image
let data_url = data.url.as_ref();
// Fetch post links and pictrs cached image
let data_url = data.url.as_ref();
- let (metadata_res, pictrs_thumbnail) =
+ let (metadata_res, thumbnail_url) =
fetch_site_data(context.client(), &context.settings(), data_url).await;
fetch_site_data(context.client(), &context.settings(), 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));
+ let (embed_title, embed_description, embed_video_url) = metadata_res
+ .map(|u| (u.title, u.description, u.embed_video_url))
+ .unwrap_or_default();
let post_form = PostForm {
name: data.name.trim().to_owned(),
let post_form = PostForm {
name: data.name.trim().to_owned(),
nsfw: data.nsfw,
embed_title,
embed_description,
nsfw: data.nsfw,
embed_title,
embed_description,
- embed_html,
- thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
+ embed_video_url,
+ thumbnail_url,
// Fetch post links and Pictrs cached image
let data_url = data.url.as_ref();
// Fetch post links and Pictrs cached image
let data_url = data.url.as_ref();
- let (metadata_res, pictrs_thumbnail) =
+ let (metadata_res, thumbnail_url) =
fetch_site_data(context.client(), &context.settings(), data_url).await;
fetch_site_data(context.client(), &context.settings(), 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));
+ let (embed_title, embed_description, embed_video_url) = metadata_res
+ .map(|u| (u.title, u.description, u.embed_video_url))
+ .unwrap_or_default();
let post_form = PostForm {
creator_id: orig_post.creator_id.to_owned(),
let post_form = PostForm {
creator_id: orig_post.creator_id.to_owned(),
updated: Some(naive_now()),
embed_title,
embed_description,
updated: Some(naive_now()),
embed_title,
embed_description,
- embed_html,
- thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
+ embed_video_url,
+ thumbnail_url,
// url sent by lemmy (old)
page.url
};
// url sent by lemmy (old)
page.url
};
- let thumbnail_url: Option<Url> = page.image.map(|i| i.url);
- let (metadata_res, pictrs_thumbnail) = if let Some(url) = &url {
+ let (metadata_res, thumbnail_url) = if let Some(url) = &url {
fetch_site_data(context.client(), &context.settings(), Some(url)).await
} else {
fetch_site_data(context.client(), &context.settings(), Some(url)).await
} else {
+ (None, page.image.map(|i| i.url.into()))
- let (embed_title, embed_description, embed_html) = metadata_res
- .map(|u| (u.title, u.description, u.html))
- .unwrap_or((None, None, None));
+ let (embed_title, embed_description, embed_video_url) = metadata_res
+ .map(|u| (u.title, u.description, u.embed_video_url))
+ .unwrap_or_default();
let body_slurs_removed =
read_from_string_or_source_opt(&page.content, &page.media_type, &page.source)
.map(|s| remove_slurs(&s, &context.settings().slur_regex()));
let body_slurs_removed =
read_from_string_or_source_opt(&page.content, &page.media_type, &page.source)
.map(|s| remove_slurs(&s, &context.settings().slur_regex()));
stickied: page.stickied,
embed_title,
embed_description,
stickied: page.stickied,
embed_title,
embed_description,
- embed_html,
- thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
+ embed_video_url,
+ thumbnail_url,
ap_id: Some(page.id.clone().into()),
local: Some(false),
}
ap_id: Some(page.id.clone().into()),
local: Some(false),
}
self.body = None;
self.embed_title = None;
self.embed_description = None;
self.body = None;
self.embed_title = None;
self.embed_description = None;
- self.embed_html = None;
+ self.embed_video_url = None;
self.thumbnail_url = None;
self
self.thumbnail_url = None;
self
updated: None,
embed_title: None,
embed_description: None,
updated: None,
embed_title: None,
embed_description: None,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
stickied -> Bool,
embed_title -> Nullable<Text>,
embed_description -> Nullable<Text>,
stickied -> Bool,
embed_title -> Nullable<Text>,
embed_description -> Nullable<Text>,
- embed_html -> Nullable<Text>,
+ embed_video_url -> Nullable<Text>,
thumbnail_url -> Nullable<Text>,
ap_id -> Varchar,
local -> Bool,
thumbnail_url -> Nullable<Text>,
ap_id -> Varchar,
local -> Bool,
pub stickied: bool,
pub embed_title: Option<String>,
pub embed_description: Option<String>,
pub stickied: bool,
pub embed_title: Option<String>,
pub embed_description: Option<String>,
- pub embed_html: Option<String>,
+ pub embed_video_url: Option<DbUrl>,
pub thumbnail_url: Option<DbUrl>,
pub ap_id: DbUrl,
pub local: bool,
pub thumbnail_url: Option<DbUrl>,
pub ap_id: DbUrl,
pub local: bool,
pub stickied: Option<bool>,
pub embed_title: Option<String>,
pub embed_description: Option<String>,
pub stickied: Option<bool>,
pub embed_title: Option<String>,
pub embed_description: Option<String>,
- pub embed_html: Option<String>,
+ pub embed_video_url: Option<DbUrl>,
pub thumbnail_url: Option<DbUrl>,
pub ap_id: Option<DbUrl>,
pub local: Option<bool>,
pub thumbnail_url: Option<DbUrl>,
pub ap_id: Option<DbUrl>,
pub local: Option<bool>,
nsfw: false,
embed_title: None,
embed_description: None,
nsfw: false,
embed_title: None,
embed_description: None,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
nsfw: false,
embed_title: None,
embed_description: None,
nsfw: false,
embed_title: None,
embed_description: None,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
--- /dev/null
+alter table post drop column embed_url;
+alter table post add column embed_video_url text;
\ No newline at end of file
--- /dev/null
+alter table post drop column embed_html;
+alter table post add column embed_video_url text;
\ No newline at end of file