mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 06:41:18 +00:00
Fixing tests, fixing issue with federated thumbnails.
This commit is contained in:
parent
2b70adf6ea
commit
857adb025b
7 changed files with 23 additions and 39 deletions
|
@ -30,6 +30,7 @@ import {
|
||||||
getPost,
|
getPost,
|
||||||
waitUntil,
|
waitUntil,
|
||||||
createPostWithThumbnail,
|
createPostWithThumbnail,
|
||||||
|
sampleImage,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
const downloadFileSync = require("download-file-sync");
|
const downloadFileSync = require("download-file-sync");
|
||||||
|
|
||||||
|
@ -182,13 +183,13 @@ test("Images in remote post are proxied if setting enabled", async () => {
|
||||||
gamma,
|
gamma,
|
||||||
community.community_view.community.id,
|
community.community_view.community.id,
|
||||||
upload.url,
|
upload.url,
|
||||||
"![](http://example.com/image2.png)",
|
`![](${sampleImage})`,
|
||||||
);
|
);
|
||||||
expect(post.post_view.post).toBeDefined();
|
expect(post.post_view.post).toBeDefined();
|
||||||
|
|
||||||
// remote image gets proxied after upload
|
// remote image gets proxied after upload
|
||||||
expect(
|
expect(
|
||||||
post.post_view.post.url?.startsWith(
|
post.post_view.post.thumbnail_url?.startsWith(
|
||||||
"http://lemmy-gamma:8561/api/v3/image_proxy?url",
|
"http://lemmy-gamma:8561/api/v3/image_proxy?url",
|
||||||
),
|
),
|
||||||
).toBeTruthy();
|
).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);
|
let epsilonPost = await resolvePost(epsilon, post.post_view.post);
|
||||||
expect(epsilonPost.post).toBeDefined();
|
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(
|
expect(
|
||||||
epsilonPost.post!.post.url?.startsWith(
|
epsilonPost2.post_view.post.thumbnail_url?.startsWith(
|
||||||
"http://lemmy-epsilon:8581/api/v3/image_proxy?url",
|
"http://lemmy-epsilon:8581/api/v3/image_proxy?url",
|
||||||
),
|
),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
expect(
|
expect(
|
||||||
epsilonPost.post!.post.body?.startsWith(
|
epsilonPost2.post_view.post.body?.startsWith(
|
||||||
"![](http://lemmy-epsilon:8581/api/v3/image_proxy?url",
|
"![](http://lemmy-epsilon:8581/api/v3/image_proxy?url",
|
||||||
),
|
),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
@ -231,7 +238,7 @@ test("No image proxying if setting is disabled", async () => {
|
||||||
alpha,
|
alpha,
|
||||||
community.community_view.community.id,
|
community.community_view.community.id,
|
||||||
upload.url,
|
upload.url,
|
||||||
"![](http://example.com/image2.png)",
|
`![](${sampleImage})`,
|
||||||
);
|
);
|
||||||
expect(post.post_view.post).toBeDefined();
|
expect(post.post_view.post).toBeDefined();
|
||||||
|
|
||||||
|
@ -239,7 +246,7 @@ test("No image proxying if setting is disabled", async () => {
|
||||||
expect(
|
expect(
|
||||||
post.post_view.post.url?.startsWith("http://127.0.0.1:8551/pictrs/image/"),
|
post.post_view.post.url?.startsWith("http://127.0.0.1:8551/pictrs/image/"),
|
||||||
).toBeTruthy();
|
).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(
|
let betaPost = await waitForPost(
|
||||||
beta,
|
beta,
|
||||||
|
@ -252,8 +259,7 @@ test("No image proxying if setting is disabled", async () => {
|
||||||
expect(
|
expect(
|
||||||
betaPost.post.url?.startsWith("http://127.0.0.1:8551/pictrs/image/"),
|
betaPost.post.url?.startsWith("http://127.0.0.1:8551/pictrs/image/"),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
expect(betaPost.post.body).toBe("![](http://example.com/image2.png)");
|
expect(betaPost.post.body).toBe(`![](${sampleImage})`);
|
||||||
|
|
||||||
// Make sure the alt text got federated
|
// Make sure the alt text got federated
|
||||||
expect(post.post_view.post.alt_text).toBe(betaPost.post.alt_text);
|
expect(post.post_view.post.alt_text).toBe(betaPost.post.alt_text);
|
||||||
});
|
});
|
||||||
|
|
|
@ -729,7 +729,7 @@ test("Block post that contains banned URL", async () => {
|
||||||
|
|
||||||
await epsilon.editSite(editSiteForm);
|
await epsilon.editSite(editSiteForm);
|
||||||
|
|
||||||
await delay(500);
|
await delay();
|
||||||
|
|
||||||
if (!betaCommunity) {
|
if (!betaCommunity) {
|
||||||
throw "Missing beta community";
|
throw "Missing beta community";
|
||||||
|
|
|
@ -81,6 +81,8 @@ import { ListingType } from "lemmy-js-client/dist/types/ListingType";
|
||||||
|
|
||||||
export const fetchFunction = fetch;
|
export const fetchFunction = fetch;
|
||||||
export const imageFetchLimit = 50;
|
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 alphaUrl = "http://127.0.0.1:8541";
|
||||||
export let betaUrl = "http://127.0.0.1:8551";
|
export let betaUrl = "http://127.0.0.1:8551";
|
||||||
|
@ -693,8 +695,8 @@ export async function saveUserSettingsBio(
|
||||||
export async function saveUserSettingsFederated(
|
export async function saveUserSettingsFederated(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
): Promise<SuccessResponse> {
|
): Promise<SuccessResponse> {
|
||||||
let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png";
|
let avatar = sampleImage;
|
||||||
let banner = "https://image.flaticon.com/icons/png/512/36/35896.png";
|
let banner = sampleImage;
|
||||||
let bio = "a changed bio";
|
let bio = "a changed bio";
|
||||||
let form: SaveUserSettings = {
|
let form: SaveUserSettings = {
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
|
|
@ -76,7 +76,6 @@ pub async fn fetch_link_metadata(url: &Url, context: &LemmyContext) -> LemmyResu
|
||||||
pub async fn generate_post_link_metadata(
|
pub async fn generate_post_link_metadata(
|
||||||
post: Post,
|
post: Post,
|
||||||
custom_thumbnail: Option<Url>,
|
custom_thumbnail: Option<Url>,
|
||||||
federated_thumbnail: Option<Url>,
|
|
||||||
send_activity: impl FnOnce(Post) -> Option<SendActivityData> + Send + 'static,
|
send_activity: impl FnOnce(Post) -> Option<SendActivityData> + Send + 'static,
|
||||||
local_site: Option<LocalSite>,
|
local_site: Option<LocalSite>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
|
@ -111,13 +110,7 @@ pub async fn generate_post_link_metadata(
|
||||||
// Use custom thumbnail if available and its not an image post
|
// Use custom thumbnail if available and its not an image post
|
||||||
if let Some(custom_thumbnail) = custom_thumbnail {
|
if let Some(custom_thumbnail) = custom_thumbnail {
|
||||||
proxy_image_link(custom_thumbnail, &context).await.ok()
|
proxy_image_link(custom_thumbnail, &context).await.ok()
|
||||||
}
|
} else if allow_generate_thumbnail {
|
||||||
// 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 {
|
|
||||||
match metadata.opengraph_data.image {
|
match metadata.opengraph_data.image {
|
||||||
Some(url) => generate_pictrs_thumbnail(&url, &context)
|
Some(url) => generate_pictrs_thumbnail(&url, &context)
|
||||||
.await
|
.await
|
||||||
|
@ -151,21 +144,12 @@ pub async fn generate_post_link_metadata(
|
||||||
pub fn generate_post_link_metadata_background(
|
pub fn generate_post_link_metadata_background(
|
||||||
post: Post,
|
post: Post,
|
||||||
custom_thumbnail: Option<Url>,
|
custom_thumbnail: Option<Url>,
|
||||||
federated_thumbnail: Option<Url>,
|
|
||||||
send_activity: impl FnOnce(Post) -> Option<SendActivityData> + Send + 'static,
|
send_activity: impl FnOnce(Post) -> Option<SendActivityData> + Send + 'static,
|
||||||
local_site: Option<LocalSite>,
|
local_site: Option<LocalSite>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) {
|
) {
|
||||||
spawn_try_task(async move {
|
spawn_try_task(async move {
|
||||||
generate_post_link_metadata(
|
generate_post_link_metadata(post, custom_thumbnail, send_activity, local_site, context).await
|
||||||
post,
|
|
||||||
custom_thumbnail,
|
|
||||||
federated_thumbnail,
|
|
||||||
send_activity,
|
|
||||||
local_site,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,6 @@ pub async fn create_post(
|
||||||
generate_post_link_metadata(
|
generate_post_link_metadata(
|
||||||
updated_post.clone(),
|
updated_post.clone(),
|
||||||
custom_thumbnail,
|
custom_thumbnail,
|
||||||
None,
|
|
||||||
|post| Some(SendActivityData::CreatePost(post)),
|
|post| Some(SendActivityData::CreatePost(post)),
|
||||||
Some(local_site),
|
Some(local_site),
|
||||||
context.reset_request_count(),
|
context.reset_request_count(),
|
||||||
|
|
|
@ -112,7 +112,6 @@ pub async fn update_post(
|
||||||
generate_post_link_metadata(
|
generate_post_link_metadata(
|
||||||
updated_post.clone(),
|
updated_post.clone(),
|
||||||
custom_thumbnail,
|
custom_thumbnail,
|
||||||
None,
|
|
||||||
|post| Some(SendActivityData::UpdatePost(post)),
|
|post| Some(SendActivityData::UpdatePost(post)),
|
||||||
Some(local_site),
|
Some(local_site),
|
||||||
context.reset_request_count(),
|
context.reset_request_count(),
|
||||||
|
|
|
@ -25,12 +25,7 @@ use html2text::{from_read_with_decorator, render::text_renderer::TrivialDecorato
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::generate_post_link_metadata_background,
|
request::generate_post_link_metadata_background,
|
||||||
utils::{
|
utils::{get_url_blocklist, local_site_opt_to_slur_regex, process_markdown_opt},
|
||||||
get_url_blocklist,
|
|
||||||
local_site_opt_to_slur_regex,
|
|
||||||
process_markdown_opt,
|
|
||||||
proxy_image_link_opt_apub,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -279,7 +274,6 @@ impl Object for ApubPost {
|
||||||
generate_post_link_metadata_background(
|
generate_post_link_metadata_background(
|
||||||
post.clone(),
|
post.clone(),
|
||||||
None,
|
None,
|
||||||
page.image.map(|i| i.url),
|
|
||||||
|_| None,
|
|_| None,
|
||||||
local_site,
|
local_site,
|
||||||
context.reset_request_count(),
|
context.reset_request_count(),
|
||||||
|
|
Loading…
Reference in a new issue