mirror of
https://github.com/Nutomic/ibis.git
synced 2025-02-09 11:54:42 +00:00
Add trailing newline to default main page text, move to server
This commit is contained in:
parent
14402e6984
commit
494527eccf
3 changed files with 94 additions and 88 deletions
|
@ -1,40 +1,22 @@
|
|||
use crate::{
|
||||
backend::{
|
||||
database::{article::DbArticleForm, instance::DbInstanceForm, IbisContext},
|
||||
federation::{activities::submit_article_update, VerifyUrlData},
|
||||
utils::{
|
||||
config::IbisConfig,
|
||||
error::{Error, MyResult},
|
||||
generate_activity_id,
|
||||
},
|
||||
},
|
||||
common::{
|
||||
article::{DbArticle, EditVersion},
|
||||
instance::DbInstance,
|
||||
user::DbPerson,
|
||||
utils::http_protocol_str,
|
||||
MAIN_PAGE_NAME,
|
||||
database::IbisContext,
|
||||
federation::VerifyUrlData,
|
||||
utils::{config::IbisConfig, error::MyResult, generate_activity_id},
|
||||
},
|
||||
common::instance::DbInstance,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
config::{Data, FederationConfig},
|
||||
fetch::object_id::ObjectId,
|
||||
};
|
||||
use chrono::Utc;
|
||||
use activitypub_federation::config::FederationConfig;
|
||||
use diesel::{
|
||||
r2d2::{ConnectionManager, Pool},
|
||||
PgConnection,
|
||||
};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use federation::objects::{
|
||||
articles_collection::local_articles_url,
|
||||
instance_collection::linked_instances_url,
|
||||
};
|
||||
use log::info;
|
||||
use server::start_server;
|
||||
use server::{setup::setup, start_server};
|
||||
use std::{net::SocketAddr, thread};
|
||||
use tokio::sync::oneshot;
|
||||
use utils::{generate_keypair, scheduled_tasks};
|
||||
use utils::scheduled_tasks;
|
||||
|
||||
pub mod api;
|
||||
pub mod database;
|
||||
|
@ -82,66 +64,3 @@ pub async fn start(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const MAIN_PAGE_DEFAULT_TEXT: &str = "Welcome to Ibis, the federated Wikipedia alternative!
|
||||
|
||||
This main page can only be edited by the admin. Use it as an introduction for new users, \
|
||||
and to list interesting articles.";
|
||||
|
||||
async fn setup(context: &Data<IbisContext>) -> Result<(), Error> {
|
||||
let domain = &context.config.federation.domain;
|
||||
let ap_id = ObjectId::parse(&format!("{}://{domain}", http_protocol_str()))?;
|
||||
let inbox_url = format!("{}://{domain}/inbox", http_protocol_str());
|
||||
let keypair = generate_keypair()?;
|
||||
let form = DbInstanceForm {
|
||||
domain: domain.to_string(),
|
||||
ap_id,
|
||||
articles_url: Some(local_articles_url(domain)?),
|
||||
instances_url: Some(linked_instances_url(domain)?),
|
||||
inbox_url,
|
||||
public_key: keypair.public_key,
|
||||
private_key: Some(keypair.private_key),
|
||||
last_refreshed_at: Utc::now(),
|
||||
local: true,
|
||||
topic: None,
|
||||
name: None,
|
||||
};
|
||||
let instance = DbInstance::create(&form, context)?;
|
||||
|
||||
let person = DbPerson::create_local(
|
||||
context.config.setup.admin_username.clone(),
|
||||
context.config.setup.admin_password.clone(),
|
||||
true,
|
||||
context,
|
||||
)?;
|
||||
|
||||
// Create the main page which is shown by default
|
||||
let form = DbArticleForm {
|
||||
title: MAIN_PAGE_NAME.to_string(),
|
||||
text: String::new(),
|
||||
ap_id: ObjectId::parse(&format!(
|
||||
"{}://{domain}/article/{MAIN_PAGE_NAME}",
|
||||
http_protocol_str()
|
||||
))?,
|
||||
instance_id: instance.id,
|
||||
local: true,
|
||||
protected: true,
|
||||
approved: true,
|
||||
};
|
||||
let article = DbArticle::create(form, context)?;
|
||||
// also create an article so its included in most recently edited list
|
||||
submit_article_update(
|
||||
MAIN_PAGE_DEFAULT_TEXT.to_string(),
|
||||
"Default main page".to_string(),
|
||||
EditVersion::default(),
|
||||
&article,
|
||||
person.person.id,
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// create ghost user
|
||||
DbPerson::ghost(context)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ use tower_layer::Layer;
|
|||
mod assets;
|
||||
mod middleware;
|
||||
mod nodeinfo;
|
||||
pub(super) mod setup;
|
||||
|
||||
pub(super) async fn start_server(
|
||||
context: FederationConfig<IbisContext>,
|
||||
|
|
86
src/backend/server/setup.rs
Normal file
86
src/backend/server/setup.rs
Normal file
|
@ -0,0 +1,86 @@
|
|||
use crate::{
|
||||
backend::{
|
||||
database::{article::DbArticleForm, instance::DbInstanceForm, IbisContext},
|
||||
federation::{
|
||||
activities::submit_article_update,
|
||||
objects::{
|
||||
articles_collection::local_articles_url,
|
||||
instance_collection::linked_instances_url,
|
||||
},
|
||||
},
|
||||
utils::{error::Error, generate_keypair},
|
||||
},
|
||||
common::{
|
||||
article::{DbArticle, EditVersion},
|
||||
instance::DbInstance,
|
||||
user::DbPerson,
|
||||
utils::http_protocol_str,
|
||||
MAIN_PAGE_NAME,
|
||||
},
|
||||
};
|
||||
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
|
||||
use chrono::Utc;
|
||||
|
||||
const MAIN_PAGE_DEFAULT_TEXT: &str = "Welcome to Ibis, the federated Wikipedia alternative!
|
||||
|
||||
This main page can only be edited by the admin. Use it as an introduction for new users, \
|
||||
and to list interesting articles.
|
||||
";
|
||||
|
||||
pub async fn setup(context: &Data<IbisContext>) -> Result<(), Error> {
|
||||
let domain = &context.config.federation.domain;
|
||||
let ap_id = ObjectId::parse(&format!("{}://{domain}", http_protocol_str()))?;
|
||||
let inbox_url = format!("{}://{domain}/inbox", http_protocol_str());
|
||||
let keypair = generate_keypair()?;
|
||||
let form = DbInstanceForm {
|
||||
domain: domain.to_string(),
|
||||
ap_id,
|
||||
articles_url: Some(local_articles_url(domain)?),
|
||||
instances_url: Some(linked_instances_url(domain)?),
|
||||
inbox_url,
|
||||
public_key: keypair.public_key,
|
||||
private_key: Some(keypair.private_key),
|
||||
last_refreshed_at: Utc::now(),
|
||||
local: true,
|
||||
topic: None,
|
||||
name: None,
|
||||
};
|
||||
let instance = DbInstance::create(&form, context)?;
|
||||
|
||||
let person = DbPerson::create_local(
|
||||
context.config.setup.admin_username.clone(),
|
||||
context.config.setup.admin_password.clone(),
|
||||
true,
|
||||
context,
|
||||
)?;
|
||||
|
||||
// Create the main page which is shown by default
|
||||
let form = DbArticleForm {
|
||||
title: MAIN_PAGE_NAME.to_string(),
|
||||
text: String::new(),
|
||||
ap_id: ObjectId::parse(&format!(
|
||||
"{}://{domain}/article/{MAIN_PAGE_NAME}",
|
||||
http_protocol_str()
|
||||
))?,
|
||||
instance_id: instance.id,
|
||||
local: true,
|
||||
protected: true,
|
||||
approved: true,
|
||||
};
|
||||
let article = DbArticle::create(form, context)?;
|
||||
// also create an article so its included in most recently edited list
|
||||
submit_article_update(
|
||||
MAIN_PAGE_DEFAULT_TEXT.to_string(),
|
||||
"Default main page".to_string(),
|
||||
EditVersion::default(),
|
||||
&article,
|
||||
person.person.id,
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// create ghost user
|
||||
DbPerson::ghost(context)?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue