mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Changing to fetch_site_data
This commit is contained in:
parent
41d752523b
commit
29bf57d410
4 changed files with 8 additions and 9 deletions
|
@ -20,7 +20,7 @@ use lemmy_apub::{
|
||||||
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
|
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
|
||||||
use lemmy_db_schema::source::post::*;
|
use lemmy_db_schema::source::post::*;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
request::fetch_site_metadata_and_pictrs_data,
|
request::fetch_site_data,
|
||||||
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
|
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
|
||||||
ApiError,
|
ApiError,
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
|
@ -51,8 +51,7 @@ impl PerformCrud for CreatePost {
|
||||||
|
|
||||||
// Fetch post links and pictrs cached image
|
// Fetch post links and pictrs cached image
|
||||||
let data_url = data.url.as_ref();
|
let data_url = data.url.as_ref();
|
||||||
let (metadata_res, pictrs_thumbnail) =
|
let (metadata_res, pictrs_thumbnail) = fetch_site_data(context.client(), data_url).await;
|
||||||
fetch_site_metadata_and_pictrs_data(context.client(), data_url).await;
|
|
||||||
let (embed_title, embed_description, embed_html) = metadata_res
|
let (embed_title, embed_description, embed_html) = metadata_res
|
||||||
.map(|u| (u.title, u.description, u.html))
|
.map(|u| (u.title, u.description, u.html))
|
||||||
.unwrap_or((None, None, None));
|
.unwrap_or((None, None, None));
|
||||||
|
|
|
@ -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_queries::{source::post::Post_, Crud};
|
||||||
use lemmy_db_schema::{naive_now, source::post::*};
|
use lemmy_db_schema::{naive_now, source::post::*};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
request::fetch_site_metadata_and_pictrs_data,
|
request::fetch_site_data,
|
||||||
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
|
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
|
||||||
ApiError,
|
ApiError,
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
|
@ -51,8 +51,7 @@ impl PerformCrud for EditPost {
|
||||||
|
|
||||||
// Fetch post links and Pictrs cached image
|
// Fetch post links and Pictrs cached image
|
||||||
let data_url = data.url.as_ref();
|
let data_url = data.url.as_ref();
|
||||||
let (metadata_res, pictrs_thumbnail) =
|
let (metadata_res, pictrs_thumbnail) = fetch_site_data(context.client(), data_url).await;
|
||||||
fetch_site_metadata_and_pictrs_data(context.client(), data_url).await;
|
|
||||||
let (embed_title, embed_description, embed_html) = metadata_res
|
let (embed_title, embed_description, embed_html) = metadata_res
|
||||||
.map(|u| (u.title, u.description, u.html))
|
.map(|u| (u.title, u.description, u.html))
|
||||||
.unwrap_or((None, None, None));
|
.unwrap_or((None, None, None));
|
||||||
|
|
|
@ -31,7 +31,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
request::fetch_site_metadata_and_pictrs_data,
|
request::fetch_site_data,
|
||||||
utils::{check_slurs, convert_datetime, markdown_to_html, remove_slurs},
|
utils::{check_slurs, convert_datetime, markdown_to_html, remove_slurs},
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
|
@ -189,7 +189,7 @@ impl FromApub for Post {
|
||||||
|
|
||||||
let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
|
let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
|
||||||
let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.url {
|
let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.url {
|
||||||
fetch_site_metadata_and_pictrs_data(context.client(), Some(url)).await
|
fetch_site_data(context.client(), Some(url)).await
|
||||||
} else {
|
} else {
|
||||||
(None, thumbnail_url)
|
(None, thumbnail_url)
|
||||||
};
|
};
|
||||||
|
|
|
@ -148,7 +148,8 @@ pub(crate) async fn fetch_pictrs(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Both are options, since the URL might be either an html page, or an image
|
/// Both are options, since the URL might be either an html page, or an image
|
||||||
pub async fn fetch_site_metadata_and_pictrs_data(
|
/// Returns the SiteMetadata, and a Pictrs URL, if there is a picture associated
|
||||||
|
pub async fn fetch_site_data(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
url: Option<&Url>,
|
url: Option<&Url>,
|
||||||
) -> (Option<SiteMetadata>, Option<Url>) {
|
) -> (Option<SiteMetadata>, Option<Url>) {
|
||||||
|
|
Loading…
Reference in a new issue