mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-30 00:01:25 +00:00
parent
ad75192bae
commit
6ff2ec3dac
14 changed files with 214 additions and 165 deletions
|
@ -63,11 +63,13 @@ async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance
|
||||||
|
|
||||||
// Create a local site, since this is necessary for determining if email verification is
|
// Create a local site, since this is necessary for determining if email verification is
|
||||||
// required
|
// required
|
||||||
let mut local_site_form = LocalSiteInsertForm::new(site.id);
|
let local_site_form = LocalSiteInsertForm {
|
||||||
local_site_form.require_email_verification = Some(true);
|
require_email_verification: Some(true),
|
||||||
local_site_form.application_question = Some(".".to_string());
|
application_question: Some(".".to_string()),
|
||||||
local_site_form.registration_mode = Some(RegistrationMode::RequireApplication);
|
registration_mode: Some(RegistrationMode::RequireApplication),
|
||||||
local_site_form.site_setup = Some(true);
|
site_setup: Some(true),
|
||||||
|
..LocalSiteInsertForm::new(site.id)
|
||||||
|
};
|
||||||
let local_site = LocalSite::create(pool, &local_site_form).await.unwrap();
|
let local_site = LocalSite::create(pool, &local_site_form).await.unwrap();
|
||||||
|
|
||||||
// Required to have a working local SiteView when updating the site to change email verification
|
// Required to have a working local SiteView when updating the site to change email verification
|
||||||
|
|
|
@ -111,9 +111,10 @@ pub async fn create_comment(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut comment_form =
|
let comment_form = CommentInsertForm {
|
||||||
CommentInsertForm::new(local_user_view.person.id, data.post_id, content.clone());
|
language_id,
|
||||||
comment_form.language_id = language_id;
|
..CommentInsertForm::new(local_user_view.person.id, data.post_id, content.clone())
|
||||||
|
};
|
||||||
|
|
||||||
// Create the comment
|
// Create the comment
|
||||||
let parent_path = parent_opt.clone().map(|t| t.path);
|
let parent_path = parent_opt.clone().map(|t| t.path);
|
||||||
|
|
|
@ -88,23 +88,25 @@ pub async fn create_community(
|
||||||
// When you create a community, make sure the user becomes a moderator and a follower
|
// When you create a community, make sure the user becomes a moderator and a follower
|
||||||
let keypair = generate_actor_keypair()?;
|
let keypair = generate_actor_keypair()?;
|
||||||
|
|
||||||
let mut community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm {
|
||||||
site_view.site.instance_id,
|
description,
|
||||||
data.name.clone(),
|
icon,
|
||||||
data.title.clone(),
|
banner,
|
||||||
keypair.public_key,
|
nsfw: data.nsfw,
|
||||||
);
|
actor_id: Some(community_actor_id.clone()),
|
||||||
community_form.description = description;
|
private_key: Some(keypair.private_key),
|
||||||
community_form.icon = icon;
|
followers_url: Some(generate_followers_url(&community_actor_id)?),
|
||||||
community_form.banner = banner;
|
inbox_url: Some(generate_inbox_url(&community_actor_id)?),
|
||||||
community_form.nsfw = data.nsfw;
|
shared_inbox_url: Some(generate_shared_inbox_url(context.settings())?),
|
||||||
community_form.actor_id = Some(community_actor_id.clone());
|
posting_restricted_to_mods: data.posting_restricted_to_mods,
|
||||||
community_form.private_key = Some(keypair.private_key);
|
visibility: data.visibility,
|
||||||
community_form.followers_url = Some(generate_followers_url(&community_actor_id)?);
|
..CommunityInsertForm::new(
|
||||||
community_form.inbox_url = Some(generate_inbox_url(&community_actor_id)?);
|
site_view.site.instance_id,
|
||||||
community_form.shared_inbox_url = Some(generate_shared_inbox_url(context.settings())?);
|
data.name.clone(),
|
||||||
community_form.posting_restricted_to_mods = data.posting_restricted_to_mods;
|
data.title.clone(),
|
||||||
community_form.visibility = data.visibility;
|
keypair.public_key,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -130,16 +130,18 @@ pub async fn create_post(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut post_form = PostInsertForm::new(
|
let post_form = PostInsertForm {
|
||||||
data.name.trim().to_string(),
|
url: url.map(Into::into),
|
||||||
local_user_view.person.id,
|
body,
|
||||||
data.community_id,
|
alt_text: data.alt_text.clone(),
|
||||||
);
|
nsfw: data.nsfw,
|
||||||
post_form.url = url.map(Into::into);
|
language_id,
|
||||||
post_form.body = body;
|
..PostInsertForm::new(
|
||||||
post_form.alt_text = data.alt_text.clone();
|
data.name.trim().to_string(),
|
||||||
post_form.nsfw = data.nsfw;
|
local_user_view.person.id,
|
||||||
post_form.language_id = language_id;
|
data.community_id,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut context.pool(), &post_form)
|
let inserted_post = Post::create(&mut context.pool(), &post_form)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -151,14 +151,16 @@ pub(crate) mod tests {
|
||||||
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
||||||
create_local_site(context, instance.id).await?;
|
create_local_site(context, instance.id).await?;
|
||||||
|
|
||||||
let mut community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm {
|
||||||
instance.id,
|
deleted: Some(deleted),
|
||||||
"testcom6".to_string(),
|
visibility: Some(visibility),
|
||||||
"nada".to_owned(),
|
..CommunityInsertForm::new(
|
||||||
"pubkey".to_string(),
|
instance.id,
|
||||||
);
|
"testcom6".to_string(),
|
||||||
community_form.deleted = Some(deleted);
|
"nada".to_owned(),
|
||||||
community_form.visibility = Some(visibility);
|
"pubkey".to_string(),
|
||||||
|
)
|
||||||
|
};
|
||||||
let community = Community::create(&mut context.pool(), &community_form).await?;
|
let community = Community::create(&mut context.pool(), &community_form).await?;
|
||||||
Ok((instance, community))
|
Ok((instance, community))
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,28 +151,30 @@ impl Object for ApubCommunity {
|
||||||
let icon = proxy_image_link_opt_apub(group.icon.map(|i| i.url), context).await?;
|
let icon = proxy_image_link_opt_apub(group.icon.map(|i| i.url), context).await?;
|
||||||
let banner = proxy_image_link_opt_apub(group.image.map(|i| i.url), context).await?;
|
let banner = proxy_image_link_opt_apub(group.image.map(|i| i.url), context).await?;
|
||||||
|
|
||||||
let mut form = CommunityInsertForm::new(
|
let form = CommunityInsertForm {
|
||||||
instance_id,
|
published: group.published,
|
||||||
group.preferred_username.clone(),
|
updated: group.updated,
|
||||||
group.name.unwrap_or(group.preferred_username.clone()),
|
deleted: Some(false),
|
||||||
group.public_key.public_key_pem,
|
nsfw: Some(group.sensitive.unwrap_or(false)),
|
||||||
);
|
actor_id: Some(group.id.into()),
|
||||||
form.published = group.published;
|
local: Some(false),
|
||||||
form.updated = group.updated;
|
last_refreshed_at: Some(naive_now()),
|
||||||
form.deleted = Some(false);
|
icon,
|
||||||
form.nsfw = Some(group.sensitive.unwrap_or(false));
|
banner,
|
||||||
form.actor_id = Some(group.id.into());
|
description,
|
||||||
form.local = Some(false);
|
followers_url: group.followers.clone().map(Into::into),
|
||||||
form.last_refreshed_at = Some(naive_now());
|
inbox_url: Some(group.inbox.into()),
|
||||||
form.icon = icon;
|
shared_inbox_url: group.endpoints.map(|e| e.shared_inbox.into()),
|
||||||
form.banner = banner;
|
moderators_url: group.attributed_to.clone().map(Into::into),
|
||||||
form.description = description;
|
posting_restricted_to_mods: group.posting_restricted_to_mods,
|
||||||
form.followers_url = group.followers.clone().map(Into::into);
|
featured_url: group.featured.clone().map(Into::into),
|
||||||
form.inbox_url = Some(group.inbox.into());
|
..CommunityInsertForm::new(
|
||||||
form.shared_inbox_url = group.endpoints.map(|e| e.shared_inbox.into());
|
instance_id,
|
||||||
form.moderators_url = group.attributed_to.clone().map(Into::into);
|
group.preferred_username.clone(),
|
||||||
form.posting_restricted_to_mods = group.posting_restricted_to_mods;
|
group.name.unwrap_or(group.preferred_username.clone()),
|
||||||
form.featured_url = group.featured.clone().map(Into::into);
|
group.public_key.public_key_pem,
|
||||||
|
)
|
||||||
|
};
|
||||||
let languages =
|
let languages =
|
||||||
LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
|
LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
|
||||||
|
|
||||||
|
|
|
@ -247,17 +247,19 @@ impl Object for ApubPost {
|
||||||
let language_id =
|
let language_id =
|
||||||
LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?;
|
LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?;
|
||||||
|
|
||||||
let mut form = PostInsertForm::new(name, creator.id, community.id);
|
let form = PostInsertForm {
|
||||||
form.url = url.map(Into::into);
|
url: url.map(Into::into),
|
||||||
form.body = body;
|
body,
|
||||||
form.alt_text = alt_text;
|
alt_text,
|
||||||
form.published = page.published.map(Into::into);
|
published: page.published.map(Into::into),
|
||||||
form.updated = page.updated.map(Into::into);
|
updated: page.updated.map(Into::into),
|
||||||
form.deleted = Some(false);
|
deleted: Some(false),
|
||||||
form.nsfw = page.sensitive;
|
nsfw: page.sensitive,
|
||||||
form.ap_id = Some(page.id.clone().into());
|
ap_id: Some(page.id.clone().into()),
|
||||||
form.local = Some(false);
|
local: Some(false),
|
||||||
form.language_id = language_id;
|
language_id,
|
||||||
|
..PostInsertForm::new(name, creator.id, community.id)
|
||||||
|
};
|
||||||
|
|
||||||
let timestamp = page.updated.or(page.published).unwrap_or_else(naive_now);
|
let timestamp = page.updated.or(page.published).unwrap_or_else(naive_now);
|
||||||
let post = Post::insert_apub(&mut context.pool(), timestamp, &form).await?;
|
let post = Post::insert_apub(&mut context.pool(), timestamp, &form).await?;
|
||||||
|
|
|
@ -51,8 +51,10 @@ impl Instance {
|
||||||
Some(i) => Ok(i),
|
Some(i) => Ok(i),
|
||||||
None => {
|
None => {
|
||||||
// Instance not in database yet, insert it
|
// Instance not in database yet, insert it
|
||||||
let mut form = InstanceForm::new(domain_);
|
let form = InstanceForm {
|
||||||
form.updated = Some(naive_now());
|
updated: Some(naive_now()),
|
||||||
|
..InstanceForm::new(domain_)
|
||||||
|
};
|
||||||
insert_into(instance::table)
|
insert_into(instance::table)
|
||||||
.values(&form)
|
.values(&form)
|
||||||
// Necessary because this method may be called concurrently for the same domain. This
|
// Necessary because this method may be called concurrently for the same domain. This
|
||||||
|
|
|
@ -515,53 +515,63 @@ mod tests {
|
||||||
// 3 4
|
// 3 4
|
||||||
// \
|
// \
|
||||||
// 5
|
// 5
|
||||||
let mut comment_form_0 = CommentInsertForm::new(
|
let comment_form_0 = CommentInsertForm {
|
||||||
inserted_timmy_person.id,
|
language_id: english_id,
|
||||||
inserted_post.id,
|
..CommentInsertForm::new(
|
||||||
"Comment 0".into(),
|
inserted_timmy_person.id,
|
||||||
);
|
inserted_post.id,
|
||||||
comment_form_0.language_id = english_id;
|
"Comment 0".into(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let inserted_comment_0 = Comment::create(pool, &comment_form_0, None).await?;
|
let inserted_comment_0 = Comment::create(pool, &comment_form_0, None).await?;
|
||||||
|
|
||||||
let mut comment_form_1 = CommentInsertForm::new(
|
let comment_form_1 = CommentInsertForm {
|
||||||
inserted_sara_person.id,
|
language_id: english_id,
|
||||||
inserted_post.id,
|
..CommentInsertForm::new(
|
||||||
"Comment 1, A test blocked comment".into(),
|
inserted_sara_person.id,
|
||||||
);
|
inserted_post.id,
|
||||||
comment_form_1.language_id = english_id;
|
"Comment 1, A test blocked comment".into(),
|
||||||
|
)
|
||||||
|
};
|
||||||
let inserted_comment_1 =
|
let inserted_comment_1 =
|
||||||
Comment::create(pool, &comment_form_1, Some(&inserted_comment_0.path)).await?;
|
Comment::create(pool, &comment_form_1, Some(&inserted_comment_0.path)).await?;
|
||||||
|
|
||||||
let finnish_id = Language::read_id_from_code(pool, Some("fi")).await?;
|
let finnish_id = Language::read_id_from_code(pool, Some("fi")).await?;
|
||||||
let mut comment_form_2 = CommentInsertForm::new(
|
let comment_form_2 = CommentInsertForm {
|
||||||
inserted_timmy_person.id,
|
language_id: finnish_id,
|
||||||
inserted_post.id,
|
..CommentInsertForm::new(
|
||||||
"Comment 2".into(),
|
inserted_timmy_person.id,
|
||||||
);
|
inserted_post.id,
|
||||||
comment_form_2.language_id = finnish_id;
|
"Comment 2".into(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let inserted_comment_2 =
|
let inserted_comment_2 =
|
||||||
Comment::create(pool, &comment_form_2, Some(&inserted_comment_0.path)).await?;
|
Comment::create(pool, &comment_form_2, Some(&inserted_comment_0.path)).await?;
|
||||||
|
|
||||||
let mut comment_form_3 = CommentInsertForm::new(
|
let comment_form_3 = CommentInsertForm {
|
||||||
inserted_timmy_person.id,
|
language_id: english_id,
|
||||||
inserted_post.id,
|
..CommentInsertForm::new(
|
||||||
"Comment 3".into(),
|
inserted_timmy_person.id,
|
||||||
);
|
inserted_post.id,
|
||||||
comment_form_3.language_id = english_id;
|
"Comment 3".into(),
|
||||||
|
)
|
||||||
|
};
|
||||||
let _inserted_comment_3 =
|
let _inserted_comment_3 =
|
||||||
Comment::create(pool, &comment_form_3, Some(&inserted_comment_1.path)).await?;
|
Comment::create(pool, &comment_form_3, Some(&inserted_comment_1.path)).await?;
|
||||||
|
|
||||||
let polish_id = Language::read_id_from_code(pool, Some("pl"))
|
let polish_id = Language::read_id_from_code(pool, Some("pl"))
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::LanguageNotAllowed)?;
|
.ok_or(LemmyErrorType::LanguageNotAllowed)?;
|
||||||
let mut comment_form_4 = CommentInsertForm::new(
|
let comment_form_4 = CommentInsertForm {
|
||||||
inserted_timmy_person.id,
|
language_id: Some(polish_id),
|
||||||
inserted_post.id,
|
..CommentInsertForm::new(
|
||||||
"Comment 4".into(),
|
inserted_timmy_person.id,
|
||||||
);
|
inserted_post.id,
|
||||||
comment_form_4.language_id = Some(polish_id);
|
"Comment 4".into(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let inserted_comment_4 =
|
let inserted_comment_4 =
|
||||||
Comment::create(pool, &comment_form_4, Some(&inserted_comment_1.path)).await?;
|
Comment::create(pool, &comment_form_4, Some(&inserted_comment_1.path)).await?;
|
||||||
|
|
|
@ -850,12 +850,14 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut post_from_blocked_person = PostInsertForm::new(
|
let post_from_blocked_person = PostInsertForm {
|
||||||
POST_BY_BLOCKED_PERSON.to_string(),
|
language_id: Some(LanguageId(1)),
|
||||||
inserted_blocked_person.id,
|
..PostInsertForm::new(
|
||||||
inserted_community.id,
|
POST_BY_BLOCKED_PERSON.to_string(),
|
||||||
);
|
inserted_blocked_person.id,
|
||||||
post_from_blocked_person.language_id = Some(LanguageId(1));
|
inserted_community.id,
|
||||||
|
)
|
||||||
|
};
|
||||||
Post::create(pool, &post_from_blocked_person).await?;
|
Post::create(pool, &post_from_blocked_person).await?;
|
||||||
|
|
||||||
// block that person
|
// block that person
|
||||||
|
@ -867,9 +869,10 @@ mod tests {
|
||||||
PersonBlock::block(pool, &person_block).await?;
|
PersonBlock::block(pool, &person_block).await?;
|
||||||
|
|
||||||
// A sample post
|
// A sample post
|
||||||
let mut new_post =
|
let new_post = PostInsertForm {
|
||||||
PostInsertForm::new(POST.to_string(), inserted_person.id, inserted_community.id);
|
language_id: Some(LanguageId(47)),
|
||||||
new_post.language_id = Some(LanguageId(47));
|
..PostInsertForm::new(POST.to_string(), inserted_person.id, inserted_community.id)
|
||||||
|
};
|
||||||
let inserted_post = Post::create(pool, &new_post).await?;
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let new_bot_post = PostInsertForm::new(
|
let new_bot_post = PostInsertForm::new(
|
||||||
|
@ -1031,13 +1034,15 @@ mod tests {
|
||||||
let data = init_data(pool).await?;
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
// A post which contains the search them 'Post' not in the title (but in the body)
|
// A post which contains the search them 'Post' not in the title (but in the body)
|
||||||
let mut new_post = PostInsertForm::new(
|
let new_post = PostInsertForm {
|
||||||
POST_WITH_ANOTHER_TITLE.to_string(),
|
language_id: Some(LanguageId(47)),
|
||||||
data.local_user_view.person.id,
|
body: Some("Post".to_string()),
|
||||||
data.inserted_community.id,
|
..PostInsertForm::new(
|
||||||
);
|
POST_WITH_ANOTHER_TITLE.to_string(),
|
||||||
new_post.language_id = Some(LanguageId(47));
|
data.local_user_view.person.id,
|
||||||
new_post.body = Some("Post".to_string());
|
data.inserted_community.id,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let inserted_post = Post::create(pool, &new_post).await?;
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
|
@ -1267,12 +1272,14 @@ mod tests {
|
||||||
.await?
|
.await?
|
||||||
.expect("french should exist");
|
.expect("french should exist");
|
||||||
|
|
||||||
let mut post_spanish = PostInsertForm::new(
|
let post_spanish = PostInsertForm {
|
||||||
EL_POSTO.to_string(),
|
language_id: Some(spanish_id),
|
||||||
data.local_user_view.person.id,
|
..PostInsertForm::new(
|
||||||
data.inserted_community.id,
|
EL_POSTO.to_string(),
|
||||||
);
|
data.local_user_view.person.id,
|
||||||
post_spanish.language_id = Some(spanish_id);
|
data.inserted_community.id,
|
||||||
|
)
|
||||||
|
};
|
||||||
Post::create(pool, &post_spanish).await?;
|
Post::create(pool, &post_spanish).await?;
|
||||||
|
|
||||||
let post_listings_all = data.default_post_query().list(&data.site, pool).await?;
|
let post_listings_all = data.default_post_query().list(&data.site, pool).await?;
|
||||||
|
@ -1408,12 +1415,14 @@ mod tests {
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &community_form).await?;
|
let inserted_community = Community::create(pool, &community_form).await?;
|
||||||
|
|
||||||
let mut post_form = PostInsertForm::new(
|
let post_form = PostInsertForm {
|
||||||
POST_FROM_BLOCKED_INSTANCE.to_string(),
|
language_id: Some(LanguageId(1)),
|
||||||
data.inserted_bot.id,
|
..PostInsertForm::new(
|
||||||
inserted_community.id,
|
POST_FROM_BLOCKED_INSTANCE.to_string(),
|
||||||
);
|
data.inserted_bot.id,
|
||||||
post_form.language_id = Some(LanguageId(1));
|
inserted_community.id,
|
||||||
|
)
|
||||||
|
};
|
||||||
let post_from_blocked_instance = Post::create(pool, &post_form).await?;
|
let post_from_blocked_instance = Post::create(pool, &post_form).await?;
|
||||||
|
|
||||||
// no instance block, should return all posts
|
// no instance block, should return all posts
|
||||||
|
@ -1471,14 +1480,16 @@ mod tests {
|
||||||
// and featured
|
// and featured
|
||||||
for comments in 0..10 {
|
for comments in 0..10 {
|
||||||
for _ in 0..15 {
|
for _ in 0..15 {
|
||||||
let mut post_form = PostInsertForm::new(
|
let post_form = PostInsertForm {
|
||||||
"keep Christ in Christmas".to_owned(),
|
featured_local: Some((comments % 2) == 0),
|
||||||
data.local_user_view.person.id,
|
featured_community: Some((comments % 2) == 0),
|
||||||
inserted_community.id,
|
published: Some(Utc::now() - Duration::from_secs(comments % 3)),
|
||||||
);
|
..PostInsertForm::new(
|
||||||
post_form.featured_local = Some((comments % 2) == 0);
|
"keep Christ in Christmas".to_owned(),
|
||||||
post_form.featured_community = Some((comments % 2) == 0);
|
data.local_user_view.person.id,
|
||||||
post_form.published = Some(Utc::now() - Duration::from_secs(comments % 3));
|
inserted_community.id,
|
||||||
|
)
|
||||||
|
};
|
||||||
let inserted_post = Post::create(pool, &post_form).await?;
|
let inserted_post = Post::create(pool, &post_form).await?;
|
||||||
inserted_post_ids.push(inserted_post.id);
|
inserted_post_ids.push(inserted_post.id);
|
||||||
|
|
||||||
|
|
|
@ -354,8 +354,10 @@ mod test {
|
||||||
let mut data = TestData::init(1, 1).await?;
|
let mut data = TestData::init(1, 1).await?;
|
||||||
|
|
||||||
let instance = &data.instances[0];
|
let instance = &data.instances[0];
|
||||||
let mut form = InstanceForm::new(instance.domain.clone());
|
let form = InstanceForm {
|
||||||
form.updated = DateTime::from_timestamp(0, 0);
|
updated: DateTime::from_timestamp(0, 0),
|
||||||
|
..InstanceForm::new(instance.domain.clone())
|
||||||
|
};
|
||||||
Instance::update(&mut data.context.pool(), instance.id, form).await?;
|
Instance::update(&mut data.context.pool(), instance.id, form).await?;
|
||||||
|
|
||||||
data.run().await?;
|
data.run().await?;
|
||||||
|
|
|
@ -290,8 +290,10 @@ impl InstanceWorker {
|
||||||
if updated.add(Days::new(1)) < Utc::now() {
|
if updated.add(Days::new(1)) < Utc::now() {
|
||||||
self.instance.updated = Some(Utc::now());
|
self.instance.updated = Some(Utc::now());
|
||||||
|
|
||||||
let mut form = InstanceForm::new(self.instance.domain.clone());
|
let form = InstanceForm {
|
||||||
form.updated = Some(naive_now());
|
updated: Some(naive_now()),
|
||||||
|
..InstanceForm::new(self.instance.domain.clone())
|
||||||
|
};
|
||||||
Instance::update(&mut self.pool(), self.instance.id, form).await?;
|
Instance::update(&mut self.pool(), self.instance.id, form).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -485,31 +485,38 @@ async fn initialize_local_site_2022_10_10(
|
||||||
.clone()
|
.clone()
|
||||||
.map(|s| s.site_name)
|
.map(|s| s.site_name)
|
||||||
.unwrap_or_else(|| "New Site".to_string());
|
.unwrap_or_else(|| "New Site".to_string());
|
||||||
let mut site_form = SiteInsertForm::new(name, instance.id);
|
let site_form = SiteInsertForm {
|
||||||
site_form.actor_id = Some(site_actor_id.clone().into());
|
actor_id: Some(site_actor_id.clone().into()),
|
||||||
site_form.last_refreshed_at = Some(naive_now());
|
last_refreshed_at: Some(naive_now()),
|
||||||
site_form.inbox_url = Some(generate_shared_inbox_url(settings)?);
|
inbox_url: Some(generate_shared_inbox_url(settings)?),
|
||||||
site_form.private_key = Some(site_key_pair.private_key);
|
private_key: Some(site_key_pair.private_key),
|
||||||
site_form.public_key = Some(site_key_pair.public_key);
|
public_key: Some(site_key_pair.public_key),
|
||||||
|
|
||||||
|
..SiteInsertForm::new(name, instance.id)
|
||||||
|
};
|
||||||
let site = Site::create(pool, &site_form).await?;
|
let site = Site::create(pool, &site_form).await?;
|
||||||
|
|
||||||
// Finally create the local_site row
|
// Finally create the local_site row
|
||||||
let mut local_site_form = LocalSiteInsertForm::new(site.id);
|
let local_site_form = LocalSiteInsertForm {
|
||||||
local_site_form.site_setup = Some(settings.setup.is_some());
|
site_setup: Some(settings.setup.is_some()),
|
||||||
|
..LocalSiteInsertForm::new(site.id)
|
||||||
|
};
|
||||||
let local_site = LocalSite::create(pool, &local_site_form).await?;
|
let local_site = LocalSite::create(pool, &local_site_form).await?;
|
||||||
|
|
||||||
// Create the rate limit table
|
// Create the rate limit table
|
||||||
let mut local_site_rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id);
|
let local_site_rate_limit_form = LocalSiteRateLimitInsertForm {
|
||||||
|
message: Some(999),
|
||||||
|
post: Some(999),
|
||||||
|
register: Some(999),
|
||||||
|
image: Some(999),
|
||||||
|
comment: Some(999),
|
||||||
|
search: Some(999),
|
||||||
|
..LocalSiteRateLimitInsertForm::new(local_site.id)
|
||||||
|
};
|
||||||
// TODO these have to be set, because the database defaults are too low for the federation
|
// TODO these have to be set, because the database defaults are too low for the federation
|
||||||
// tests to pass, and there's no way to live update the rate limits without restarting the
|
// tests to pass, and there's no way to live update the rate limits without restarting the
|
||||||
// server.
|
// server.
|
||||||
// This can be removed once live rate limits are enabled.
|
// This can be removed once live rate limits are enabled.
|
||||||
local_site_rate_limit_form.message = Some(999);
|
|
||||||
local_site_rate_limit_form.post = Some(999);
|
|
||||||
local_site_rate_limit_form.register = Some(999);
|
|
||||||
local_site_rate_limit_form.image = Some(999);
|
|
||||||
local_site_rate_limit_form.comment = Some(999);
|
|
||||||
local_site_rate_limit_form.search = Some(999);
|
|
||||||
LocalSiteRateLimit::create(pool, &local_site_rate_limit_form).await?;
|
LocalSiteRateLimit::create(pool, &local_site_rate_limit_form).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -493,8 +493,10 @@ async fn build_update_instance_form(
|
||||||
// not every Fediverse instance has a valid Nodeinfo endpoint (its not required for
|
// not every Fediverse instance has a valid Nodeinfo endpoint (its not required for
|
||||||
// Activitypub). That's why we always need to mark instances as updated if they are
|
// Activitypub). That's why we always need to mark instances as updated if they are
|
||||||
// alive.
|
// alive.
|
||||||
let mut instance_form = InstanceForm::new(domain.to_string());
|
let instance_form = InstanceForm {
|
||||||
instance_form.updated = Some(naive_now());
|
updated: Some(naive_now()),
|
||||||
|
..InstanceForm::new(domain.to_string())
|
||||||
|
};
|
||||||
|
|
||||||
// First, fetch their /.well-known/nodeinfo, then extract the correct nodeinfo link from it
|
// First, fetch their /.well-known/nodeinfo, then extract the correct nodeinfo link from it
|
||||||
let well_known_url = format!("https://{}/.well-known/nodeinfo", domain);
|
let well_known_url = format!("https://{}/.well-known/nodeinfo", domain);
|
||||||
|
|
Loading…
Reference in a new issue