diff --git a/.config/example.yml b/.config/example.yml index ffc8a1d34..70fb38de6 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -8,7 +8,12 @@ #───┘ URL └───────────────────────────────────────────────────── # Final accessible URL seen by a user. -url: https://example.com/ +url: https://example.org/ + +# (Optional - ADVANCED) Domain used for account handles. +# Only uncomment this if you want to for example have the URL be ice.example.org +# and the handles to be example.org +# accountDomain: example.org # ┌───────────────────────┐ #───┘ Port and TLS settings └─────────────────────────────────── diff --git a/packages/backend/native-utils/migration/src/lib.rs b/packages/backend/native-utils/migration/src/lib.rs index a6f2fd5c9..476db3306 100644 --- a/packages/backend/native-utils/migration/src/lib.rs +++ b/packages/backend/native-utils/migration/src/lib.rs @@ -4,6 +4,7 @@ mod m20230531_180824_drop_reversi; mod m20230627_185451_index_note_url; mod m20230709_000510_move_antenna_to_cache; mod m20230726_213530_drop_ads; +mod m20230801_160334_add_instance_account_domain; pub struct Migrator; @@ -15,6 +16,7 @@ impl MigratorTrait for Migrator { Box::new(m20230627_185451_index_note_url::Migration), Box::new(m20230709_000510_move_antenna_to_cache::Migration), Box::new(m20230726_213530_drop_ads::Migration), + Box::new(m20230801_160334_add_instance_account_domain::Migration), ] } } diff --git a/packages/backend/native-utils/migration/src/m20230801_160334_add_instance_account_domain.rs b/packages/backend/native-utils/migration/src/m20230801_160334_add_instance_account_domain.rs new file mode 100644 index 000000000..cbc26c902 --- /dev/null +++ b/packages/backend/native-utils/migration/src/m20230801_160334_add_instance_account_domain.rs @@ -0,0 +1,36 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Instance::Table) + .add_column(ColumnDef::new(Instance::AccountDomain).string()) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Instance::Table) + .drop_column(Instance::AccountDomain) + .to_owned(), + ) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Instance { + Table, + AccountDomain, +} diff --git a/packages/backend/native-utils/src/model/entity/instance.rs b/packages/backend/native-utils/src/model/entity/instance.rs index fc9c5bf8b..c79b2c757 100644 --- a/packages/backend/native-utils/src/model/entity/instance.rs +++ b/packages/backend/native-utils/src/model/entity/instance.rs @@ -10,6 +10,7 @@ pub struct Model { #[sea_orm(column_name = "caughtAt")] pub caught_at: DateTimeWithTimeZone, pub host: String, + pub account_domain: Option, #[sea_orm(column_name = "usersCount")] pub users_count: i32, #[sea_orm(column_name = "notesCount")] diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index 2535b8c91..824f03f5d 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -63,7 +63,7 @@ export async function masterMain() { } bootLogger.succ( - `Now listening on port ${config.port} on ${config.url}`, + `Now listening on port ${config.port} on ${config.url} - using ${config.accountDomain}`, null, true, ); diff --git a/packages/backend/src/config/load.ts b/packages/backend/src/config/load.ts index 7a67c4bd3..0d40fccae 100644 --- a/packages/backend/src/config/load.ts +++ b/packages/backend/src/config/load.ts @@ -40,6 +40,8 @@ export default function load() { config.url = url.origin; + if (!config.accountDomain) config.accountDomain = url.hostname + config.port = config.port || parseInt(process.env.PORT || "", 10); mixin.version = meta.version; diff --git a/packages/backend/src/config/types.ts b/packages/backend/src/config/types.ts index 7789c26e0..d41bf4831 100644 --- a/packages/backend/src/config/types.ts +++ b/packages/backend/src/config/types.ts @@ -5,6 +5,7 @@ export type Source = { repository_url?: string; feedback_url?: string; url: string; + accountDomain?: string; port: number; disableHsts?: boolean; db: { diff --git a/packages/backend/src/models/entities/instance.ts b/packages/backend/src/models/entities/instance.ts index 7e0b08583..83c88e284 100644 --- a/packages/backend/src/models/entities/instance.ts +++ b/packages/backend/src/models/entities/instance.ts @@ -170,4 +170,9 @@ export class Instance { nullable: true, }) public infoUpdatedAt: Date | null; + + @Column("Domains for account ats", { + nullable: true, + }) + public accountDomain: string | null; } diff --git a/packages/backend/src/models/repositories/instance.ts b/packages/backend/src/models/repositories/instance.ts index 667ec948d..bc50836e2 100644 --- a/packages/backend/src/models/repositories/instance.ts +++ b/packages/backend/src/models/repositories/instance.ts @@ -34,6 +34,7 @@ export const InstanceRepository = db.getRepository(Instance).extend({ iconUrl: instance.iconUrl, faviconUrl: instance.faviconUrl, themeColor: instance.themeColor, + accountDomain: instance.accountDomain, infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null, diff --git a/packages/backend/src/models/schema/federation-instance.ts b/packages/backend/src/models/schema/federation-instance.ts index 7a8af7f51..868510c46 100644 --- a/packages/backend/src/models/schema/federation-instance.ts +++ b/packages/backend/src/models/schema/federation-instance.ts @@ -21,6 +21,12 @@ export const packedFederationInstanceSchema = { nullable: false, example: "firefish.example.com", }, + accountDomain: { + type: "string", + optional: true, + nullable: true, + example: "example.com", + }, usersCount: { type: "number", optional: false, diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index a6c1e399a..1dfb43ffd 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -32,7 +32,7 @@ export async function resolveUser( host = toPuny(host); - if (config.host === host) { + if (config.host === host || config.accountDomain === host) { logger.info(`return local user: ${usernameLower}`); return await Users.findOneBy({ usernameLower, host: IsNull() }).then( (u) => { diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index c8556aa6b..2ffaf6a64 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -18,6 +18,7 @@ export async function getInstance( return { uri: response.uri, + account_domain: config.accountDomain, title: response.title || "Iceshrimp", short_description: response.description?.substring(0, 50) || "See real server website",