diff --git a/api_tests/src/image.spec.ts b/api_tests/src/image.spec.ts index 7326420ca..2a65c4752 100644 --- a/api_tests/src/image.spec.ts +++ b/api_tests/src/image.spec.ts @@ -30,6 +30,7 @@ import { getPost, waitUntil, createPostWithThumbnail, + sampleImage, } from "./shared"; const downloadFileSync = require("download-file-sync"); @@ -182,13 +183,13 @@ test("Images in remote post are proxied if setting enabled", async () => { gamma, community.community_view.community.id, upload.url, - "![](http://example.com/image2.png)", + `![](${sampleImage})`, ); expect(post.post_view.post).toBeDefined(); // remote image gets proxied after upload expect( - post.post_view.post.url?.startsWith( + post.post_view.post.thumbnail_url?.startsWith( "http://lemmy-gamma:8561/api/v3/image_proxy?url", ), ).toBeTruthy(); @@ -201,14 +202,20 @@ test("Images in remote post are proxied if setting enabled", async () => { let epsilonPost = await resolvePost(epsilon, post.post_view.post); expect(epsilonPost.post).toBeDefined(); - // remote image gets proxied after federation + // Fetch the post again, the metadata should be backgrounded now + // Wait for the metadata to get fetched, since this is backgrounded now + let epsilonPost2 = await waitUntil( + () => getPost(epsilon, epsilonPost.post!.post.id), + p => p.post_view.post.thumbnail_url != undefined, + ); + expect( - epsilonPost.post!.post.url?.startsWith( + epsilonPost2.post_view.post.thumbnail_url?.startsWith( "http://lemmy-epsilon:8581/api/v3/image_proxy?url", ), ).toBeTruthy(); expect( - epsilonPost.post!.post.body?.startsWith( + epsilonPost2.post_view.post.body?.startsWith( "![](http://lemmy-epsilon:8581/api/v3/image_proxy?url", ), ).toBeTruthy(); @@ -231,7 +238,7 @@ test("No image proxying if setting is disabled", async () => { alpha, community.community_view.community.id, upload.url, - "![](http://example.com/image2.png)", + `![](${sampleImage})`, ); expect(post.post_view.post).toBeDefined(); @@ -239,7 +246,7 @@ test("No image proxying if setting is disabled", async () => { expect( post.post_view.post.url?.startsWith("http://127.0.0.1:8551/pictrs/image/"), ).toBeTruthy(); - expect(post.post_view.post.body).toBe("![](http://example.com/image2.png)"); + expect(post.post_view.post.body).toBe(`![](${sampleImage})`); let betaPost = await waitForPost( beta, @@ -252,8 +259,7 @@ test("No image proxying if setting is disabled", async () => { expect( betaPost.post.url?.startsWith("http://127.0.0.1:8551/pictrs/image/"), ).toBeTruthy(); - expect(betaPost.post.body).toBe("![](http://example.com/image2.png)"); - + expect(betaPost.post.body).toBe(`![](${sampleImage})`); // Make sure the alt text got federated expect(post.post_view.post.alt_text).toBe(betaPost.post.alt_text); }); diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index b2ab50222..38cf79fcb 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -729,7 +729,7 @@ test("Block post that contains banned URL", async () => { await epsilon.editSite(editSiteForm); - await delay(500); + await delay(); if (!betaCommunity) { throw "Missing beta community"; diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 1a8a9afaf..a1bbb1277 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -81,6 +81,8 @@ import { ListingType } from "lemmy-js-client/dist/types/ListingType"; export const fetchFunction = fetch; export const imageFetchLimit = 50; +export const sampleImage = + "https://i.pinimg.com/originals/df/5f/5b/df5f5b1b174a2b4b6026cc6c8f9395c1.jpg"; export let alphaUrl = "http://127.0.0.1:8541"; export let betaUrl = "http://127.0.0.1:8551"; @@ -693,8 +695,8 @@ export async function saveUserSettingsBio( export async function saveUserSettingsFederated( api: LemmyHttp, ): Promise { - let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png"; - let banner = "https://image.flaticon.com/icons/png/512/36/35896.png"; + let avatar = sampleImage; + let banner = sampleImage; let bio = "a changed bio"; let form: SaveUserSettings = { show_nsfw: false, diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index 934e45c0c..bca48b8ca 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -76,7 +76,6 @@ pub async fn fetch_link_metadata(url: &Url, context: &LemmyContext) -> LemmyResu pub async fn generate_post_link_metadata( post: Post, custom_thumbnail: Option, - federated_thumbnail: Option, send_activity: impl FnOnce(Post) -> Option + Send + 'static, local_site: Option, context: Data, @@ -111,13 +110,7 @@ pub async fn generate_post_link_metadata( // Use custom thumbnail if available and its not an image post if let Some(custom_thumbnail) = custom_thumbnail { proxy_image_link(custom_thumbnail, &context).await.ok() - } - // Use federated thumbnail if available - else if let Some(federated_thumbnail) = federated_thumbnail { - proxy_image_link(federated_thumbnail, &context).await.ok() - } - // Generate local thumbnail if allowed - else if allow_generate_thumbnail { + } else if allow_generate_thumbnail { match metadata.opengraph_data.image { Some(url) => generate_pictrs_thumbnail(&url, &context) .await @@ -151,21 +144,12 @@ pub async fn generate_post_link_metadata( pub fn generate_post_link_metadata_background( post: Post, custom_thumbnail: Option, - federated_thumbnail: Option, send_activity: impl FnOnce(Post) -> Option + Send + 'static, local_site: Option, context: Data, ) { spawn_try_task(async move { - generate_post_link_metadata( - post, - custom_thumbnail, - federated_thumbnail, - send_activity, - local_site, - context, - ) - .await + generate_post_link_metadata(post, custom_thumbnail, send_activity, local_site, context).await }) } diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 58ae4e6cf..82a208a9c 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -157,7 +157,6 @@ pub async fn create_post( generate_post_link_metadata( updated_post.clone(), custom_thumbnail, - None, |post| Some(SendActivityData::CreatePost(post)), Some(local_site), context.reset_request_count(), diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 3737079a0..4b4bd9845 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -112,7 +112,6 @@ pub async fn update_post( generate_post_link_metadata( updated_post.clone(), custom_thumbnail, - None, |post| Some(SendActivityData::UpdatePost(post)), Some(local_site), context.reset_request_count(), diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index bdada86b6..53ee6e0b1 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -25,12 +25,7 @@ use html2text::{from_read_with_decorator, render::text_renderer::TrivialDecorato use lemmy_api_common::{ context::LemmyContext, request::generate_post_link_metadata_background, - utils::{ - get_url_blocklist, - local_site_opt_to_slur_regex, - process_markdown_opt, - proxy_image_link_opt_apub, - }, + utils::{get_url_blocklist, local_site_opt_to_slur_regex, process_markdown_opt}, }; use lemmy_db_schema::{ source::{ @@ -279,7 +274,6 @@ impl Object for ApubPost { generate_post_link_metadata_background( post.clone(), None, - page.image.map(|i| i.url), |_| None, local_site, context.reset_request_count(),