Skip to content

Commit

Permalink
Merge branch 'LemmyNet:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Jun 4, 2024
2 parents 3d5303b + a947474 commit eae6ed6
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 93 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.19.4-rc.5"
version = "0.19.4-rc.6"
edition = "2021"
description = "A link aggregator for the fediverse"
license = "AGPL-3.0"
Expand Down Expand Up @@ -88,17 +88,17 @@ unused_self = "deny"
unwrap_used = "deny"

[workspace.dependencies]
lemmy_api = { version = "=0.19.4-rc.5", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.4-rc.5", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.4-rc.5", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.4-rc.5", path = "./crates/utils", default-features = false }
lemmy_db_schema = { version = "=0.19.4-rc.5", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.4-rc.5", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.4-rc.5", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.4-rc.5", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.4-rc.5", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.4-rc.5", path = "./crates/db_views_moderator" }
lemmy_federate = { version = "=0.19.4-rc.5", path = "./crates/federate" }
lemmy_api = { version = "=0.19.4-rc.6", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.4-rc.6", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.4-rc.6", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.4-rc.6", path = "./crates/utils", default-features = false }
lemmy_db_schema = { version = "=0.19.4-rc.6", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.4-rc.6", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.4-rc.6", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.4-rc.6", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.4-rc.6", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.4-rc.6", path = "./crates/db_views_moderator" }
lemmy_federate = { version = "=0.19.4-rc.6", path = "./crates/federate" }
activitypub_federation = { version = "0.5.6", default-features = false, features = [
"actix-web",
] }
Expand Down
8 changes: 7 additions & 1 deletion api_tests/src/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,16 @@ test("Set a new avatar, old avatar is deleted", async () => {
expect(upload2.url).toBeDefined();

let form2 = {
avatar: upload1.url,
avatar: upload2.url,
};
await saveUserSettings(alpha, form2);
// make sure only the new avatar is kept
const listMediaRes2 = await alphaImage.listMedia();
expect(listMediaRes2.images.length).toBe(1);

// Upload that same form2 avatar, make sure it isn't replaced / deleted
await saveUserSettings(alpha, form2);
// make sure only the new avatar is kept
const listMediaRes3 = await alphaImage.listMedia();
expect(listMediaRes3.images.length).toBe(1);
});
13 changes: 8 additions & 5 deletions crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,19 @@ async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Lemm
}
}

/// When adding a new avatar or similar image, delete the old one.
/// When adding a new avatar, banner or similar image, delete the old one.
pub async fn replace_image(
new_image: &Option<String>,
old_image: &Option<DbUrl>,
context: &Data<LemmyContext>,
) -> LemmyResult<()> {
if new_image.is_some() {
// Ignore errors because image may be stored externally.
if let Some(avatar) = &old_image {
let image = LocalImage::delete_by_url(&mut context.pool(), avatar)
if let (Some(new_image), Some(old_image)) = (new_image, old_image) {
// Note: Oftentimes front ends will include the current image in the form.
// In this case, deleting `old_image` would also be deletion of `new_image`,
// so the deletion must be skipped for the image to be kept.
if new_image != old_image.as_str() {
// Ignore errors because image may be stored externally.
let image = LocalImage::delete_by_url(&mut context.pool(), old_image)
.await
.ok();
if let Some(image) = image {
Expand Down
15 changes: 9 additions & 6 deletions crates/routes/src/nodeinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use url::Url;

/// A description of the nodeinfo endpoint is here:
/// https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md
pub fn config(cfg: &mut web::ServiceConfig) {
cfg
.route(
"/nodeinfo/2.1.json",
"/nodeinfo/2.1",
web::get().to(node_info).wrap(cache_1hour()),
)
.service(web::redirect("/version", "/nodeinfo/2.1.json"))
.service(web::redirect("/version", "/nodeinfo/2.1"))
// For backwards compatibility, can be removed after Lemmy 0.20
.service(web::redirect("/nodeinfo/2.0.json", "/nodeinfo/2.1.json"))
.service(web::redirect("/nodeinfo/2.0.json", "/nodeinfo/2.1"))
.service(web::redirect("/nodeinfo/2.1.json", "/nodeinfo/2.1"))
.route(
"/.well-known/nodeinfo",
web::get().to(node_info_well_known).wrap(cache_3days()),
Expand All @@ -32,7 +35,7 @@ async fn node_info_well_known(context: web::Data<LemmyContext>) -> LemmyResult<H
links: vec![NodeInfoWellKnownLinks {
rel: Url::parse("http://nodeinfo.diaspora.software/ns/schema/2.1")?,
href: Url::parse(&format!(
"{}/nodeinfo/2.1.json",
"{}/nodeinfo/2.1",
&context.settings().get_protocol_and_hostname(),
))?,
}],
Expand Down Expand Up @@ -79,12 +82,12 @@ async fn node_info(context: web::Data<LemmyContext>) -> Result<HttpResponse, Err
}

#[derive(Serialize, Deserialize, Debug)]
struct NodeInfoWellKnown {
pub struct NodeInfoWellKnown {
pub links: Vec<NodeInfoWellKnownLinks>,
}

#[derive(Serialize, Deserialize, Debug)]
struct NodeInfoWellKnownLinks {
pub struct NodeInfoWellKnownLinks {
pub rel: Url,
pub href: Url,
}
Expand Down
Loading

0 comments on commit eae6ed6

Please sign in to comment.