Finish up support for local split domain configurations

This commit is contained in:
Laura Hausmann 2023-09-05 21:04:30 +02:00
parent c6dee2da09
commit 84867f1c13
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
23 changed files with 65 additions and 30 deletions

View File

@ -6,6 +6,7 @@ mod m20230709_000510_move_antenna_to_cache;
mod m20230726_213530_drop_ads; mod m20230726_213530_drop_ads;
mod m20230801_160334_add_instance_account_domain; mod m20230801_160334_add_instance_account_domain;
mod m20230802_190415_fix_instance_account_domain; mod m20230802_190415_fix_instance_account_domain;
mod m20230905_210205_drop_instance_account_domain;
pub struct Migrator; pub struct Migrator;
@ -19,6 +20,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230726_213530_drop_ads::Migration), Box::new(m20230726_213530_drop_ads::Migration),
Box::new(m20230801_160334_add_instance_account_domain::Migration), Box::new(m20230801_160334_add_instance_account_domain::Migration),
Box::new(m20230802_190415_fix_instance_account_domain::Migration), Box::new(m20230802_190415_fix_instance_account_domain::Migration),
Box::new(m20230905_210205_drop_instance_account_domain::Migration),
] ]
} }
} }

View File

@ -0,0 +1,37 @@
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)
.drop_column(Instance::AccountDomain)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Instance::Table)
.add_column(ColumnDef::new(Instance::AccountDomain).string())
.to_owned(),
)
.await
}
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum Instance {
Table,
#[iden = "accountDomain"]
AccountDomain,
}

View File

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

View File

@ -63,7 +63,7 @@ export async function masterMain() {
} }
bootLogger.succ( bootLogger.succ(
`Now listening on port ${config.port} on ${config.url} - using ${config.accountDomain}`, `Now listening on port ${config.port} on ${config.url} - using ${config.domain}`,
null, null,
true, true,
); );

View File

@ -40,8 +40,6 @@ export default function load() {
config.url = url.origin; config.url = url.origin;
if (!config.accountDomain) config.accountDomain = url.hostname
config.port = config.port || parseInt(process.env.PORT || "", 10); config.port = config.port || parseInt(process.env.PORT || "", 10);
config.images = { config.images = {
@ -54,6 +52,7 @@ export default function load() {
mixin.version = meta.version; mixin.version = meta.version;
mixin.host = url.host; mixin.host = url.host;
mixin.hostname = url.hostname; mixin.hostname = url.hostname;
mixin.domain = config.accountDomain ?? url.host;
mixin.scheme = url.protocol.replace(/:$/, ""); mixin.scheme = url.protocol.replace(/:$/, "");
mixin.wsScheme = mixin.scheme.replace("http", "ws"); mixin.wsScheme = mixin.scheme.replace("http", "ws");
mixin.wsUrl = `${mixin.wsScheme}://${mixin.host}`; mixin.wsUrl = `${mixin.wsScheme}://${mixin.host}`;

View File

@ -164,6 +164,7 @@ export type Mixin = {
version: string; version: string;
host: string; host: string;
hostname: string; hostname: string;
domain: string;
scheme: string; scheme: string;
wsScheme: string; wsScheme: string;
apiUrl: string; apiUrl: string;

View File

@ -345,7 +345,7 @@ export default hasConfig
userHost: userHost:
note.userHost !== "" note.userHost !== ""
? note.userHost ? note.userHost
: url.parse(config.host).host, : config.domain,
channelId: note.channelId ? note.channelId : "", channelId: note.channelId ? note.channelId : "",
mediaAttachment: attachmentType, mediaAttachment: attachmentType,
userName: note.user?.username ?? "UNKNOWN", userName: note.user?.username ?? "UNKNOWN",

View File

@ -5,12 +5,12 @@ import { toASCII } from "punycode";
export function getFullApAccount(username: string, host: string | null) { export function getFullApAccount(username: string, host: string | null) {
return host return host
? `${username}@${toPuny(host)}` ? `${username}@${toPuny(host)}`
: `${username}@${toPuny(config.host)}`; : `${username}@${toPuny(config.domain)}`;
} }
export function isSelfHost(host: string) { export function isSelfHost(host: string) {
if (host == null) return true; if (host == null) return true;
return toPuny(config.host) === toPuny(host); return toPuny(config.domain) === toPuny(host) || toPuny(config.host) === toPuny(host);
} }
export function extractDbHost(uri: string) { export function extractDbHost(uri: string) {

View File

@ -170,10 +170,4 @@ export class Instance {
nullable: true, nullable: true,
}) })
public infoUpdatedAt: Date | null; public infoUpdatedAt: Date | null;
@Column("varchar", {
length: 128,
comment: "Domain for account ATs",
})
public accountDomain: string | null;
} }

View File

@ -34,7 +34,6 @@ export const InstanceRepository = db.getRepository(Instance).extend({
iconUrl: instance.iconUrl, iconUrl: instance.iconUrl,
faviconUrl: instance.faviconUrl, faviconUrl: instance.faviconUrl,
themeColor: instance.themeColor, themeColor: instance.themeColor,
accountDomain: instance.accountDomain,
infoUpdatedAt: instance.infoUpdatedAt infoUpdatedAt: instance.infoUpdatedAt
? instance.infoUpdatedAt.toISOString() ? instance.infoUpdatedAt.toISOString()
: null, : null,

View File

@ -21,12 +21,6 @@ export const packedFederationInstanceSchema = {
nullable: false, nullable: false,
example: "iceshrimp.example.com", example: "iceshrimp.example.com",
}, },
accountDomain: {
type: "string",
optional: true,
nullable: true,
example: "example.com",
},
usersCount: { usersCount: {
type: "number", type: "number",
optional: false, optional: false,

View File

@ -46,6 +46,7 @@ export async function checkFetch(req: IncomingMessage): Promise<number> {
if ( if (
meta.privateMode && meta.privateMode &&
host !== config.host && host !== config.host &&
host !== config.domain &&
!meta.allowedHosts.includes(host) !meta.allowedHosts.includes(host)
) { ) {
return 403; return 403;

View File

@ -108,6 +108,7 @@ export default class Resolver {
if ( if (
meta.privateMode && meta.privateMode &&
config.host !== host && config.host !== host &&
config.domain !== host &&
!meta.allowedHosts.includes(host) !meta.allowedHosts.includes(host)
) { ) {
throw new Error("Instance is not allowed"); throw new Error("Instance is not allowed");

View File

@ -36,7 +36,7 @@ export async function resolveUser(
// Also return local user if host part is specified but referencing the local instance // Also return local user if host part is specified but referencing the local instance
if (config.host === host || config.accountDomain === host) { if (config.host === host || config.domain === host) {
logger.info(`return local user: ${usernameLower}`); logger.info(`return local user: ${usernameLower}`);
return await Users.findOneBy({ usernameLower, host: IsNull() }).then( return await Users.findOneBy({ usernameLower, host: IsNull() }).then(
(u) => { (u) => {

View File

@ -44,6 +44,13 @@ export const meta = {
format: "url", format: "url",
example: "https://iceshrimp.example.com", example: "https://iceshrimp.example.com",
}, },
domain: {
type: "string",
optional: false,
nullable: false,
format: "domain",
example: "example.com",
},
description: { description: {
type: "string", type: "string",
optional: false, optional: false,
@ -411,6 +418,7 @@ export default define(meta, paramDef, async (ps, me) => {
name: instance.name, name: instance.name,
uri: config.url, uri: config.url,
domain: config.domain,
description: instance.description, description: instance.description,
langs: instance.langs, langs: instance.langs,
tosUrl: instance.ToSUrl, tosUrl: instance.ToSUrl,

View File

@ -18,7 +18,6 @@ export async function getInstance(
return { return {
uri: response.uri, uri: response.uri,
account_domain: config.accountDomain,
title: response.title || "Iceshrimp", title: response.title || "Iceshrimp",
short_description: short_description:
response.description?.substring(0, 50) || "See real server website", response.description?.substring(0, 50) || "See real server website",

View File

@ -112,7 +112,7 @@ router.get("/avatar/@:acct", async (ctx) => {
const user = await Users.findOne({ const user = await Users.findOne({
where: { where: {
usernameLower: username.toLowerCase(), usernameLower: username.toLowerCase(),
host: host == null || host === config.host ? IsNull() : host, host: host == null || host === config.host || host === config.domain ? IsNull() : host,
isSuspended: false, isSuspended: false,
}, },
relations: ["avatar"], relations: ["avatar"],

View File

@ -14,7 +14,7 @@ export default async function (
) { ) {
const author = { const author = {
link: `${config.url}/@${user.username}`, link: `${config.url}/@${user.username}`,
email: `${user.username}@${config.host}`, email: `${user.username}@${config.domain}`,
name: user.name || user.username, name: user.name || user.username,
}; };
@ -41,7 +41,7 @@ export default async function (
const feed = new Feed({ const feed = new Feed({
id: author.link, id: author.link,
title: `${author.name} (@${user.username}@${config.host})`, title: `${author.name} (@${user.username}@${config.domain})`,
updated: notes[0].createdAt, updated: notes[0].createdAt,
generator: "Iceshrimp", generator: "Iceshrimp",
description: `${user.notesCount} Notes, ${ description: `${user.notesCount} Notes, ${

View File

@ -120,7 +120,7 @@ router.get(webFingerPath, async (ctx) => {
); );
const fromAcct = (acct: Acct.Acct): FindOptionsWhere<User> | number => const fromAcct = (acct: Acct.Acct): FindOptionsWhere<User> | number =>
!acct.host || acct.host === config.host.toLowerCase() !acct.host || acct.host === config.host.toLowerCase() || acct.host === config.domain.toLowerCase()
? { ? {
usernameLower: acct.username, usernameLower: acct.username,
host: IsNull(), host: IsNull(),
@ -147,7 +147,7 @@ router.get(webFingerPath, async (ctx) => {
return; return;
} }
const subject = `acct:${user.username}@${config.host}`; const subject = `acct:${user.username}@${config.domain}`;
const self = { const self = {
rel: "self", rel: "self",
type: "application/activity+json", type: "application/activity+json",

View File

@ -59,7 +59,7 @@ export async function sendEmail(
</footer> </footer>
</main> </main>
<nav style="box-sizing: border-box; max-width: 500px; margin: 16px auto 0 auto; padding: 0 32px;"> <nav style="box-sizing: border-box; max-width: 500px; margin: 16px auto 0 auto; padding: 0 32px;">
<a href="${config.url}" style="color: #9ccfd8 !important;">${config.host}</a> <a href="${config.url}" style="color: #9ccfd8 !important;">${config.domain}</a>
</nav> </nav>
</body> </body>
</html>`, </html>`,

View File

@ -180,7 +180,7 @@ function checkForSplash() {
fetchInstanceMetaPromise.then(() => { fetchInstanceMetaPromise.then(() => {
localStorage.setItem("v", instance.version); localStorage.setItem("v", instance.version);
setHost(new URL(instance.uri).host); setHost(instance.domain);
// Init service worker // Init service worker
initializeSw(); initializeSw();

View File

@ -527,7 +527,7 @@ namespace MisskeyAPI {
meta = (m: Entity.Meta, s: Entity.Stats): MegalodonEntity.Instance => { meta = (m: Entity.Meta, s: Entity.Stats): MegalodonEntity.Instance => {
const wss = m.uri.replace(/^https:\/\//, "wss://"); const wss = m.uri.replace(/^https:\/\//, "wss://");
return { return {
uri: m.uri, uri: m.domain,
title: m.name, title: m.name,
description: m.description, description: m.description,
email: m.maintainerEmail, email: m.maintainerEmail,

View File

@ -7,6 +7,7 @@ namespace MisskeyEntity {
name: string name: string
version: string version: string
uri: string uri: string
domain: string
description: string description: string
langs: Array<string> langs: Array<string>
disableRegistration: boolean disableRegistration: boolean