mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Fix data fetching from Peertube (fixes #2689)
- Other platforms can support additional language tags. Treat those
as None instead of throwing error
- deserialize_skip_error was implemented incorrectly and failed on
array values (6d9682f4e6
)
This commit is contained in:
parent
0c8fd240a6
commit
23fabaa8d7
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -4,9 +4,9 @@ version = 3
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "activitypub_federation"
|
name = "activitypub_federation"
|
||||||
version = "0.3.4"
|
version = "0.3.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f61d7a9a1207e70140b47869fd05222e30052ddc9ccfcc43098e48396c4e176"
|
checksum = "59fbd2b7fb0aea9bdd738fc1441d34d3e7b585d60b42ed63deeac289c872f119"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -59,7 +59,7 @@ lemmy_routes = { version = "=0.17.1", path = "./crates/routes" }
|
|||||||
lemmy_db_views = { version = "=0.17.1", path = "./crates/db_views" }
|
lemmy_db_views = { version = "=0.17.1", path = "./crates/db_views" }
|
||||||
lemmy_db_views_actor = { version = "=0.17.1", path = "./crates/db_views_actor" }
|
lemmy_db_views_actor = { version = "=0.17.1", path = "./crates/db_views_actor" }
|
||||||
lemmy_db_views_moderator = { version = "=0.17.1", path = "./crates/db_views_moderator" }
|
lemmy_db_views_moderator = { version = "=0.17.1", path = "./crates/db_views_moderator" }
|
||||||
activitypub_federation = "0.3.4"
|
activitypub_federation = "0.3.5"
|
||||||
diesel = "2.0.2"
|
diesel = "2.0.2"
|
||||||
diesel_migrations = "2.0.0"
|
diesel_migrations = "2.0.0"
|
||||||
diesel-async = "0.1.1"
|
diesel-async = "0.1.1"
|
||||||
|
@ -30,7 +30,9 @@ impl PerformApub for ResolveObject {
|
|||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
||||||
let res = search_query_to_object_id(&self.q, local_user_view.is_none(), context)
|
// In release builds only allow for authenticated users to fetch remote objects
|
||||||
|
let local_only = local_user_view.is_none() && cfg!(not(debug_assertions));
|
||||||
|
let res = search_query_to_object_id(&self.q, local_only, context)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
||||||
convert_response(res, local_user_view.map(|l| l.person.id), context.pool())
|
convert_response(res, local_user_view.map(|l| l.person.id), context.pool())
|
||||||
|
@ -31,6 +31,7 @@ use lemmy_utils::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
|
use std::fmt::Debug;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
|
@ -68,7 +68,7 @@ impl LanguageTag {
|
|||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<Option<LanguageId>, LemmyError> {
|
) -> Result<Option<LanguageId>, LemmyError> {
|
||||||
let identifier = lang.map(|l| l.identifier);
|
let identifier = lang.map(|l| l.identifier);
|
||||||
let language = Language::read_id_from_code_opt(pool, identifier.as_deref()).await?;
|
let language = Language::read_id_from_code(pool, identifier.as_deref()).await?;
|
||||||
|
|
||||||
Ok(language)
|
Ok(language)
|
||||||
}
|
}
|
||||||
@ -81,10 +81,10 @@ impl LanguageTag {
|
|||||||
|
|
||||||
for l in langs {
|
for l in langs {
|
||||||
let id = l.identifier;
|
let id = l.identifier;
|
||||||
language_ids.push(Language::read_id_from_code(pool, &id).await?);
|
language_ids.push(Language::read_id_from_code(pool, Some(&id)).await?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(language_ids)
|
Ok(language_ids.into_iter().flatten().collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,15 +370,30 @@ mod tests {
|
|||||||
|
|
||||||
async fn test_langs1(pool: &DbPool) -> Vec<LanguageId> {
|
async fn test_langs1(pool: &DbPool) -> Vec<LanguageId> {
|
||||||
vec![
|
vec![
|
||||||
Language::read_id_from_code(pool, "en").await.unwrap(),
|
Language::read_id_from_code(pool, Some("en"))
|
||||||
Language::read_id_from_code(pool, "fr").await.unwrap(),
|
.await
|
||||||
Language::read_id_from_code(pool, "ru").await.unwrap(),
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
|
Language::read_id_from_code(pool, Some("fr"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
|
Language::read_id_from_code(pool, Some("ru"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
async fn test_langs2(pool: &DbPool) -> Vec<LanguageId> {
|
async fn test_langs2(pool: &DbPool) -> Vec<LanguageId> {
|
||||||
vec![
|
vec![
|
||||||
Language::read_id_from_code(pool, "fi").await.unwrap(),
|
Language::read_id_from_code(pool, Some("fi"))
|
||||||
Language::read_id_from_code(pool, "se").await.unwrap(),
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
|
Language::read_id_from_code(pool, Some("se"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,11 +618,20 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(None, def1);
|
assert_eq!(None, def1);
|
||||||
|
|
||||||
let ru = Language::read_id_from_code(pool, "ru").await.unwrap();
|
let ru = Language::read_id_from_code(pool, Some("ru"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
let test_langs3 = vec![
|
let test_langs3 = vec![
|
||||||
ru,
|
ru,
|
||||||
Language::read_id_from_code(pool, "fi").await.unwrap(),
|
Language::read_id_from_code(pool, Some("fi"))
|
||||||
Language::read_id_from_code(pool, "se").await.unwrap(),
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
|
Language::read_id_from_code(pool, Some("se"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap(),
|
||||||
];
|
];
|
||||||
LocalUserLanguage::update(pool, test_langs3, local_user.id)
|
LocalUserLanguage::update(pool, test_langs3, local_user.id)
|
||||||
.await
|
.await
|
||||||
|
@ -23,23 +23,21 @@ impl Language {
|
|||||||
language.filter(id.eq(id_)).first::<Self>(conn).await
|
language.filter(id.eq(id_)).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_id_from_code(pool: &DbPool, code_: &str) -> Result<LanguageId, Error> {
|
/// Attempts to find the given language code and return its ID. If not found, returns none.
|
||||||
let conn = &mut get_conn(pool).await?;
|
pub async fn read_id_from_code(
|
||||||
Ok(
|
|
||||||
language
|
|
||||||
.filter(code.eq(code_))
|
|
||||||
.first::<Self>(conn)
|
|
||||||
.await?
|
|
||||||
.id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn read_id_from_code_opt(
|
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
code_: Option<&str>,
|
code_: Option<&str>,
|
||||||
) -> Result<Option<LanguageId>, Error> {
|
) -> Result<Option<LanguageId>, Error> {
|
||||||
if let Some(code_) = code_ {
|
if let Some(code_) = code_ {
|
||||||
Ok(Some(Language::read_id_from_code(pool, code_).await?))
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
Ok(
|
||||||
|
language
|
||||||
|
.filter(code.eq(code_))
|
||||||
|
.first::<Self>(conn)
|
||||||
|
.await
|
||||||
|
.map(|l| l.id)
|
||||||
|
.ok(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,10 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let finnish_id = Language::read_id_from_code(pool, "fi").await.unwrap();
|
let finnish_id = Language::read_id_from_code(pool, Some("fi"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
let comment_form_2 = CommentInsertForm::builder()
|
let comment_form_2 = CommentInsertForm::builder()
|
||||||
.content("Comment 2".into())
|
.content("Comment 2".into())
|
||||||
.creator_id(inserted_person.id)
|
.creator_id(inserted_person.id)
|
||||||
@ -536,7 +539,10 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let polish_id = Language::read_id_from_code(pool, "pl").await.unwrap();
|
let polish_id = Language::read_id_from_code(pool, Some("pl"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
let comment_form_4 = CommentInsertForm::builder()
|
let comment_form_4 = CommentInsertForm::builder()
|
||||||
.content("Comment 4".into())
|
.content("Comment 4".into())
|
||||||
.creator_id(inserted_person.id)
|
.creator_id(inserted_person.id)
|
||||||
@ -747,7 +753,10 @@ mod tests {
|
|||||||
assert_eq!(5, all_languages.len());
|
assert_eq!(5, all_languages.len());
|
||||||
|
|
||||||
// change user lang to finnish, should only show single finnish comment
|
// change user lang to finnish, should only show single finnish comment
|
||||||
let finnish_id = Language::read_id_from_code(pool, "fi").await.unwrap();
|
let finnish_id = Language::read_id_from_code(pool, Some("fi"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
LocalUserLanguage::update(pool, vec![finnish_id], data.inserted_local_user.id)
|
LocalUserLanguage::update(pool, vec![finnish_id], data.inserted_local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -766,7 +775,10 @@ mod tests {
|
|||||||
assert_eq!(finnish_id, finnish_comment[0].comment.language_id);
|
assert_eq!(finnish_id, finnish_comment[0].comment.language_id);
|
||||||
|
|
||||||
// now show all comments with undetermined language (which is the default value)
|
// now show all comments with undetermined language (which is the default value)
|
||||||
let undetermined_id = Language::read_id_from_code(pool, "und").await.unwrap();
|
let undetermined_id = Language::read_id_from_code(pool, Some("und"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
LocalUserLanguage::update(pool, vec![undetermined_id], data.inserted_local_user.id)
|
LocalUserLanguage::update(pool, vec![undetermined_id], data.inserted_local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -754,7 +754,10 @@ mod tests {
|
|||||||
let pool = &build_db_pool_for_tests().await;
|
let pool = &build_db_pool_for_tests().await;
|
||||||
let data = init_data(pool).await;
|
let data = init_data(pool).await;
|
||||||
|
|
||||||
let spanish_id = Language::read_id_from_code(pool, "es").await.unwrap();
|
let spanish_id = Language::read_id_from_code(pool, Some("es"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
let post_spanish = PostInsertForm::builder()
|
let post_spanish = PostInsertForm::builder()
|
||||||
.name("asffgdsc".to_string())
|
.name("asffgdsc".to_string())
|
||||||
.creator_id(data.inserted_person.id)
|
.creator_id(data.inserted_person.id)
|
||||||
@ -776,7 +779,10 @@ mod tests {
|
|||||||
// no language filters specified, all posts should be returned
|
// no language filters specified, all posts should be returned
|
||||||
assert_eq!(3, post_listings_all.len());
|
assert_eq!(3, post_listings_all.len());
|
||||||
|
|
||||||
let french_id = Language::read_id_from_code(pool, "fr").await.unwrap();
|
let french_id = Language::read_id_from_code(pool, Some("fr"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
LocalUserLanguage::update(pool, vec![french_id], data.inserted_local_user.id)
|
LocalUserLanguage::update(pool, vec![french_id], data.inserted_local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -794,7 +800,10 @@ mod tests {
|
|||||||
assert_eq!(1, post_listing_french.len());
|
assert_eq!(1, post_listing_french.len());
|
||||||
assert_eq!(french_id, post_listing_french[0].post.language_id);
|
assert_eq!(french_id, post_listing_french[0].post.language_id);
|
||||||
|
|
||||||
let undetermined_id = Language::read_id_from_code(pool, "und").await.unwrap();
|
let undetermined_id = Language::read_id_from_code(pool, Some("und"))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
LocalUserLanguage::update(
|
LocalUserLanguage::update(
|
||||||
pool,
|
pool,
|
||||||
vec![french_id, undetermined_id],
|
vec![french_id, undetermined_id],
|
||||||
|
Loading…
Reference in New Issue
Block a user