beban work on account domains

This commit is contained in:
April John 2023-08-01 21:23:32 +02:00
parent 19489103fb
commit 701fc6d275
12 changed files with 63 additions and 3 deletions

View file

@ -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 └───────────────────────────────────

View file

@ -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),
]
}
}

View file

@ -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,
}

View file

@ -10,6 +10,7 @@ pub struct Model {
#[sea_orm(column_name = "caughtAt")]
pub caught_at: DateTimeWithTimeZone,
pub host: String,
pub account_domain: Option<String>,
#[sea_orm(column_name = "usersCount")]
pub users_count: i32,
#[sea_orm(column_name = "notesCount")]

View file

@ -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,
);

View file

@ -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;

View file

@ -5,6 +5,7 @@ export type Source = {
repository_url?: string;
feedback_url?: string;
url: string;
accountDomain?: string;
port: number;
disableHsts?: boolean;
db: {

View file

@ -170,4 +170,9 @@ export class Instance {
nullable: true,
})
public infoUpdatedAt: Date | null;
@Column("Domains for account ats", {
nullable: true,
})
public accountDomain: string | null;
}

View file

@ -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,

View file

@ -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,

View file

@ -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) => {

View file

@ -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",