Skip to content

Commit

Permalink
Merge branch 'main' into image-api-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jan 13, 2025
2 parents 4b3f2f5 + 4d17eef commit 4b94043
Show file tree
Hide file tree
Showing 88 changed files with 640 additions and 281 deletions.
99 changes: 98 additions & 1 deletion .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ steps:
when:
- event: pull_request

cargo_clippy:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets -- -D warnings
when: *slow_check_paths

# `DROP OWNED` doesn't work for default user
create_database_user:
image: postgres:16-alpine
Expand All @@ -107,6 +116,68 @@ steps:
- psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
when: *slow_check_paths

cargo_test:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
LEMMY_TEST_FAST_FEDERATION: "1"
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
commands:
# Install pg_dump for the schema setup test (must match server version)
- apt update && apt install -y lsb-release
- sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
- apt update && apt install -y postgresql-client-16
# Run tests
- cargo test --workspace --no-fail-fast
when: *slow_check_paths

check_ts_bindings:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- ./scripts/ts_bindings_check.sh
when:
- event: pull_request

# make sure api builds with default features (used by other crates relying on lemmy api)
check_api_common_default_features:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- cargo check --package lemmy_api_common
when: *slow_check_paths

lemmy_api_common_doesnt_depend_on_diesel:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- "! cargo tree -p lemmy_api_common --no-default-features -i diesel"
when: *slow_check_paths

lemmy_api_common_works_with_wasm:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- "rustup target add wasm32-unknown-unknown"
- "cargo check --target wasm32-unknown-unknown -p lemmy_api_common"
when: *slow_check_paths

check_defaults_hjson_updated:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- ./scripts/update_config_defaults.sh config/defaults_current.hjson
- diff config/defaults.hjson config/defaults_current.hjson
when: *slow_check_paths

cargo_build:
image: *rust_image
environment:
Expand All @@ -116,6 +187,32 @@ steps:
- mv target/debug/lemmy_server target/lemmy_server
when: *slow_check_paths

check_diesel_schema:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
commands:
- cp crates/db_schema/src/schema.rs tmp.schema
- target/lemmy_server migration --all run
- <<: *install_diesel_cli
- diesel print-schema
- diff tmp.schema crates/db_schema/src/schema.rs
when: *slow_check_paths

check_db_perf_tool:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
commands:
# same as scripts/db_perf.sh but without creating a new database server
- cargo run --package lemmy_db_perf -- --posts 10 --read-post-pages 1
when: *slow_check_paths

run_federation_tests:
image: node:22-bookworm-slim
environment:
Expand All @@ -127,7 +224,7 @@ steps:
- bash api_tests/prepare-drone-federation-test.sh
- cd api_tests/
- pnpm i
- pnpm api-test-image
- pnpm api-test
when: *slow_check_paths

federation_tests_server_output:
Expand Down
2 changes: 1 addition & 1 deletion api_tests/run-federation-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ killall -s1 lemmy_server || true
popd

pnpm i
pnpm api-test-image || true
pnpm api-test || true

killall -s1 lemmy_server || true
killall -s1 pict-rs || true
Expand Down
3 changes: 1 addition & 2 deletions api_tests/src/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test("Upload image and delete it", async () => {
expect(deletedListAllMediaRes.images.length).toBe(previousThumbnails - 1);
});

test.only("Purge user, uploaded image removed", async () => {
test("Purge user, uploaded image removed", async () => {
let user = await registerUser(alphaImage, alphaUrl);

// upload test image
Expand All @@ -128,7 +128,6 @@ test.only("Purge user, uploaded image removed", async () => {
};
const delete_ = await alphaImage.purgePerson(purgeForm);
expect(delete_.success).toBe(true);
console.log(upload.image_url + " should be purged");

// ensure that image is deleted
const response2 = await fetch(upload.image_url ?? "");
Expand Down
30 changes: 16 additions & 14 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CommunityId,
CommunityVisibility,
CreatePrivateMessageReport,
DeleteImageParams,
DeleteImage,
EditCommunity,
GetCommunityPendingFollowsCountResponse,
GetReplies,
Expand Down Expand Up @@ -714,13 +714,17 @@ export async function saveUserSettingsBio(
export async function saveUserSettingsFederated(
api: LemmyHttp,
): Promise<SuccessResponse> {
let avatar = sampleImage;
let banner = sampleImage;
let bio = "a changed bio";
let form: SaveUserSettings = {
show_nsfw: false,
blur_nsfw: true,
default_post_sort_type: "Hot",
default_listing_type: "All",
interface_language: "",
avatar,
banner,
display_name: "user321",
show_avatars: false,
send_notifications_to_email: false,
Expand Down Expand Up @@ -932,19 +936,17 @@ export async function deleteAllImages(api: LemmyHttp) {
const imagesRes = await api.listAllMedia({
limit: imageFetchLimit,
});
const forms = imagesRes.images.map(image => {
const form: DeleteImageParams = {
token: image.local_image.pictrs_delete_token,
filename: image.local_image.pictrs_alias,
};
return form;
});
for (const form of forms) {
console.log(
"delete image: token=" + form.token + ", name=" + form.filename,
);
await api.deleteImage(form);
}
Promise.all(
imagesRes.images
.map(image => {
const form: DeleteImage = {
token: image.local_image.pictrs_delete_token,
filename: image.local_image.pictrs_alias,
};
return form;
})
.map(form => api.deleteImage(form)),
);
}

export async function unfollows() {
Expand Down
7 changes: 1 addition & 6 deletions config/defaults.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
url: "http://localhost:8080/"
# Set a custom pictrs API key. ( Required for deleting images )
api_key: "string"
# Backwards compatibility with 0.18.1. False is equivalent to `image_mode: None`, true is
# equivalent to `image_mode: StoreLinkPreviews`.
#
# To be removed in 0.20
cache_external_link_previews: true
# Specifies how to handle remote images, so that users don't have to connect directly to remote
# servers.
image_mode:
Expand All @@ -38,7 +33,7 @@
# ensures that they can be reliably retrieved and can be resized using pict-rs APIs. However
# it also increases storage usage.
#
# This is the default behaviour, and also matches Lemmy 0.18.
# This behaviour matches Lemmy 0.18.
"StoreLinkPreviews"

# or
Expand Down
2 changes: 1 addition & 1 deletion crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub async fn delete_image_from_pictrs(
async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult<Url> {
let pictrs_config = context.settings().pictrs()?;

match pictrs_config.image_mode() {
match pictrs_config.image_mode {
PictrsImageMode::None => return Ok(image_url.clone()),
PictrsImageMode::ProxyAllImages => {
return Ok(proxy_image_link(image_url.clone(), context).await?.into())
Expand Down
4 changes: 2 additions & 2 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ pub async fn process_markdown(

markdown_check_for_blocked_urls(&text, url_blocklist)?;

if context.settings().pictrs()?.image_mode() == PictrsImageMode::ProxyAllImages {
if context.settings().pictrs()?.image_mode == PictrsImageMode::ProxyAllImages {
let (text, links) = markdown_rewrite_image_links(text);
RemoteImage::create(&mut context.pool(), links.clone()).await?;

Expand Down Expand Up @@ -1128,7 +1128,7 @@ async fn proxy_image_link_internal(
/// Rewrite a link to go through `/api/v4/image_proxy` endpoint. This is only for remote urls and
/// if image_proxy setting is enabled.
pub async fn proxy_image_link(link: Url, context: &LemmyContext) -> LemmyResult<DbUrl> {
proxy_image_link_internal(link, context.settings().pictrs()?.image_mode(), context).await
proxy_image_link_internal(link, context.settings().pictrs()?.image_mode, context).await
}

pub async fn proxy_image_link_opt_apub(
Expand Down
1 change: 0 additions & 1 deletion crates/apub/assets/lemmy/activities/block/block_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"object": "http://ds9.lemmy.ml/u/lemmy_alpha",
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main",
"target": "http://enterprise.lemmy.ml/c/main",
"type": "Block",
"removeData": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"object": "http://ds9.lemmy.ml/u/lemmy_alpha",
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main",
"target": "http://enterprise.lemmy.ml/c/main",
"type": "Block",
"removeData": true,
Expand All @@ -15,7 +14,6 @@
"id": "http://enterprise.lemmy.ml/activities/block/726f43ab-bd0e-4ab3-89c8-627e976f553c"
},
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main",
"type": "Undo",
"id": "http://enterprise.lemmy.ml/activities/undo/06a20ffb-3e32-42fb-8f4c-674b36d7c557"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"type": "Add",
"actor": "https://ds9.lemmy.ml/u/lemmy_alpha",
"object": "https://ds9.lemmy.ml/post/2",
"target": "https://ds9.lemmy.ml/c/main/featured",
"audience": "https://ds9.lemmy.ml/c/main"
"target": "https://ds9.lemmy.ml/c/main/featured"
}
1 change: 0 additions & 1 deletion crates/apub/assets/lemmy/activities/community/add_mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"object": "http://ds9.lemmy.ml/u/lemmy_alpha",
"target": "http://enterprise.lemmy.ml/c/main/moderators",
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main",
"type": "Add",
"id": "http://enterprise.lemmy.ml/activities/add/ec069147-77c3-447f-88c8-0ef1df10403f"
}
3 changes: 1 addition & 2 deletions crates/apub/assets/lemmy/activities/community/lock_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"object": "http://lemmy-alpha:8541/post/2",
"cc": ["http://lemmy-alpha:8541/c/main"],
"type": "Lock",
"audience": "http://lemmy-alpha:8541/c/main"
"type": "Lock"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"type": "Remove",
"actor": "https://ds9.lemmy.ml/u/lemmy_alpha",
"object": "https://ds9.lemmy.ml/post/2",
"target": "https://ds9.lemmy.ml/c/main/featured",
"audience": "https://ds9.lemmy.ml/c/main"
"target": "https://ds9.lemmy.ml/c/main/featured"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"cc": ["http://enterprise.lemmy.ml/c/main"],
"type": "Remove",
"target": "http://enterprise.lemmy.ml/c/main/moderators",
"audience": "http://enterprise.lemmy.ml/u/main",
"id": "http://enterprise.lemmy.ml/activities/remove/aab114f8-cfbd-4935-a5b7-e1a64603650d"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
"to": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main",
"object": "http://enterprise.lemmy.ml/post/7",
"summary": "report this post",
"type": "Flag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"object": "http://lemmy-alpha:8541/post/2",
"cc": ["http://lemmy-alpha:8541/c/main"],
"type": "Lock",
"id": "http://lemmy-alpha:8541/activities/lock/08b6fd3e-9ef3-4358-a987-8bb641f3e2c3",
"audience": "http://lemmy-alpha:8541/c/main"
"id": "http://lemmy-alpha:8541/activities/lock/08b6fd3e-9ef3-4358-a987-8bb641f3e2c3"
},
"cc": ["http://lemmy-alpha:8541/c/main"],
"type": "Undo",
"audience": "http://lemmy-alpha:8541/c/main"
"type": "Undo"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"updated": "2021-11-01T12:23:50.151874Z"
},
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main",
"type": "Update",
"id": "http://ds9.lemmy.ml/activities/update/d3717cf5-096d-473f-9530-5d52f9d51f5f"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"http://enterprise.lemmy.ml/c/main",
"http://ds9.lemmy.ml/u/lemmy_alpha"
],
"audience": "http://ds9.lemmy.ml/u/lemmy_alpha",
"content": "hello",
"mediaType": "text/html",
"source": {
Expand All @@ -24,7 +23,6 @@
"http://enterprise.lemmy.ml/c/main",
"http://ds9.lemmy.ml/u/lemmy_alpha"
],
"audience": "http://ds9.lemmy.ml/u/lemmy_alpha",
"tag": [
{
"href": "http://ds9.lemmy.ml/u/lemmy_alpha",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"http://enterprise.lemmy.ml/c/main",
"https://www.w3.org/ns/activitystreams#Public"
],
"audience": "https://enterprise.lemmy.ml/c/main",
"name": "test post",
"content": "<p>test body</p>\n",
"mediaType": "text/html",
Expand All @@ -31,7 +30,6 @@
"published": "2021-10-29T15:10:51.557399Z"
},
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "https://enterprise.lemmy.ml/c/main",
"type": "Create",
"id": "http://ds9.lemmy.ml/activities/create/eee6a57a-622f-464d-b560-73ae1fcd3ddf"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"http://enterprise.lemmy.ml/c/main",
"https://www.w3.org/ns/activitystreams#Public"
],
"audience": "https://enterprise.lemmy.ml/c/main",
"name": "test post 1",
"content": "<p>test body</p>\n",
"mediaType": "text/html",
Expand All @@ -28,7 +27,6 @@
"updated": "2021-10-29T15:11:35.976374Z"
},
"cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "https://enterprise.lemmy.ml/c/main",
"type": "Update",
"id": "http://ds9.lemmy.ml/activities/update/ab360117-e165-4de4-b7fc-906b62c98631"
}
Loading

0 comments on commit 4b94043

Please sign in to comment.