Skip to content

Commit

Permalink
refactor: rename test account to primary account
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Nov 30, 2023
1 parent 9dc0e06 commit 5d846a5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ DATABASE_URL = "sqlite://hatsu.sqlite3"
HATSU_DOMAIN = "hatsu.local"
HATSU_LISTEN_HOST = "0.0.0.0"
HATSU_LISTEN_PORT = "3939"
HATSU_TEST_ACCOUNT = "example.com"
HATSU_PRIMARY_ACCOUNT = "example.com"
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ It will crawl the feed ([JSON Feed 1.1](https://jsonfeed.org/version/1.1) / [Ato

### Environments

| Environment | Default | .env.example | Remarks |
| -------------------- | ------------------------ | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DATABASE_URL` | `sqlite://hatsu.sqlite3` | `sqlite://hatsu.sqlite3` | Should be a valid `sqlite://` or `postgres://` URL. see [sea-ql.org](https://www.sea-ql.org/SeaORM/docs/install-and-config/connection/#connection-string) |
| `HATSU_DOMAIN` | | `hatsu.local` | The domain name you assigned to this Hatsu instance. For example, `hatsu.example.com` |
| `HATSU_LISTEN_HOST` | `localhost` | `0.0.0.0` | The hostname on which Hatsu is listening. |
| `HATSU_LISTEN_PORT` | `3939` | `3939` | The port on which Hatsu is listening. |
| `HATSU_TEST_ACCOUNT` | | `example.com` | The primary account for this Hatsu instance, which cannot be removed and is used as a `signed_fetch_actor`. |
| `HATSU_ACCESS_TOKEN` | | | For accessing Admin API. (optional) |
| Environment | Default | .env.example | Remarks |
| ----------------------- | ------------------------ | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DATABASE_URL` | `sqlite://hatsu.sqlite3` | `sqlite://hatsu.sqlite3` | Should be a valid `sqlite://` or `postgres://` URL. see [sea-ql.org](https://www.sea-ql.org/SeaORM/docs/install-and-config/connection/#connection-string) |
| `HATSU_DOMAIN` | | `hatsu.local` | The domain name you assigned to this Hatsu instance. For example, `hatsu.example.com` |
| `HATSU_LISTEN_HOST` | `localhost` | `0.0.0.0` | The hostname on which Hatsu is listening. |
| `HATSU_LISTEN_PORT` | `3939` | `3939` | The port on which Hatsu is listening. |
| `HATSU_PRIMARY_ACCOUNT` | | `example.com` | The primary account for this Hatsu instance, which cannot be removed and is used as a `signed_fetch_actor`. |
| `HATSU_ACCESS_TOKEN` | | | For accessing Admin API. (optional) |

### Fediverse compatibility

Expand Down
2 changes: 1 addition & 1 deletion docs/src/developers/development-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ First copy the variables,
Set `HATSU_DOMAIN` to your prepared domain
(e.g. `hatsu.example.com` without `https://`)

and `HATSU_TEST_ACCOUNT` to your desired user domain
and `HATSU_PRIMARY_ACCOUNT` to your desired user domain
(e.g. `blog.example.com` without `https://`)

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/src/developers/development-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ First copy the variables,
Set `HATSU_DOMAIN` to your prepared domain
(e.g. `hatsu.example.com` without `https://`)

and `HATSU_TEST_ACCOUNT` to your desired user domain
and `HATSU_PRIMARY_ACCOUNT` to your desired user domain
(e.g. `blog.example.com` without `https://`)

```bash
Expand Down
4 changes: 2 additions & 2 deletions src/entities/impls/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Object for DbPost {
// kind: Default::default(),
// id: Url::parse(&format!("https://{}/o/{}", data.domain(), Uuid::now_v7()))?.into(),
// // TODO: multiple user / 多用户
// attributed_to: Url::parse(&format!("https://{}/u/{}", data.domain(), env::var("HATSU_TEST_ACCOUNT")?))?.into(),
// attributed_to: Url::parse(&format!("https://{}/u/{}", data.domain(), env::var("HATSU_PRIMARY_ACCOUNT")?))?.into(),
// // 发送给提及的用户
// // TODO: "to": ["https://{}/u/{}/followers"]
// to: vec![json.attributed_to.clone().into()],
Expand Down Expand Up @@ -132,4 +132,4 @@ impl Object for DbPost {
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
Some(DateTime::parse_from_rfc3339(&self.last_refreshed_at).unwrap().naive_local())
}
}
}
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct AppEnv {
hatsu_domain: String,
hatsu_listen_host: String,
hatsu_listen_port: String,
hatsu_test_account: String,
hatsu_primary_account: String,
}

#[tokio::main]
Expand Down Expand Up @@ -71,7 +71,7 @@ async fn main() -> Result<(), AppError> {
hatsu_domain: env::var("HATSU_DOMAIN").expect("env HATSU_DOMAIN must be set"),
hatsu_listen_host: env::var("HATSU_LISTEN_HOST").unwrap_or_else(|_| "localhost".to_string()),
hatsu_listen_port: env::var("HATSU_LISTEN_PORT").unwrap_or_else(|_| "3939".to_string()),
hatsu_test_account: env::var("HATSU_TEST_ACCOUNT").expect("env HATSU_TEST_ACCOUNT must be set"),
hatsu_primary_account: env::var("HATSU_PRIMARY_ACCOUNT").expect("env HATSU_PRIMARY_ACCOUNT must be set"),
};

// 连接数据库
Expand All @@ -86,14 +86,14 @@ async fn main() -> Result<(), AppError> {
tracing::info!("checking test account");
// 尝试读取数据库中的测试账户,如果不存在则创建
// Try to read test account in the database, if it doesn't exist then create
let test_account: DbUser = match User::find_by_id(format!("https://{}/u/{}", env.hatsu_domain, env.hatsu_test_account))
let test_account: DbUser = match User::find_by_id(format!("https://{}/u/{}", env.hatsu_domain, env.hatsu_primary_account))
.one(&conn)
.await? {
Some(test_account) => test_account,
None => {
// 根据域名创建一个 user::ActiveModel
// Create a user::ActiveModel based on the domain
let test_account = DbUser::new(&env.hatsu_domain, &env.hatsu_test_account).await?.into_active_model();
let test_account = DbUser::new(&env.hatsu_domain, &env.hatsu_primary_account).await?.into_active_model();
// 向数据库插入 user::ActiveModel,并返回一个 user::Model (DbUser)
// Inserts a user::ActiveModel into the database and returns a user::Model (DbUser).
test_account.insert(&conn).await?
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/hatsu/v0/admin/remove_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn remove_account(
.one(&data.conn)
.await? {
Some(account) => {
if account.name == data.env.hatsu_test_account {
if account.name == data.env.hatsu_primary_account {
Ok((StatusCode::BAD_REQUEST, Json(RemoveAccountResult {
name: account.name.clone(),
message: format!("The primary account for this Hatsu instance could not be removed: {}", account.name)
Expand Down

0 comments on commit 5d846a5

Please sign in to comment.