mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
Finish up support for local split domain configurations
This commit is contained in:
parent
c6dee2da09
commit
84867f1c13
23 changed files with 65 additions and 30 deletions
|
@ -6,6 +6,7 @@ mod m20230709_000510_move_antenna_to_cache;
|
|||
mod m20230726_213530_drop_ads;
|
||||
mod m20230801_160334_add_instance_account_domain;
|
||||
mod m20230802_190415_fix_instance_account_domain;
|
||||
mod m20230905_210205_drop_instance_account_domain;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
@ -19,6 +20,7 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(m20230726_213530_drop_ads::Migration),
|
||||
Box::new(m20230801_160334_add_instance_account_domain::Migration),
|
||||
Box::new(m20230802_190415_fix_instance_account_domain::Migration),
|
||||
Box::new(m20230905_210205_drop_instance_account_domain::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -10,7 +10,6 @@ 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")]
|
||||
|
|
|
@ -63,7 +63,7 @@ export async function masterMain() {
|
|||
}
|
||||
|
||||
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,
|
||||
true,
|
||||
);
|
||||
|
|
|
@ -40,8 +40,6 @@ export default function load() {
|
|||
|
||||
config.url = url.origin;
|
||||
|
||||
if (!config.accountDomain) config.accountDomain = url.hostname
|
||||
|
||||
config.port = config.port || parseInt(process.env.PORT || "", 10);
|
||||
|
||||
config.images = {
|
||||
|
@ -54,6 +52,7 @@ export default function load() {
|
|||
mixin.version = meta.version;
|
||||
mixin.host = url.host;
|
||||
mixin.hostname = url.hostname;
|
||||
mixin.domain = config.accountDomain ?? url.host;
|
||||
mixin.scheme = url.protocol.replace(/:$/, "");
|
||||
mixin.wsScheme = mixin.scheme.replace("http", "ws");
|
||||
mixin.wsUrl = `${mixin.wsScheme}://${mixin.host}`;
|
||||
|
|
|
@ -164,6 +164,7 @@ export type Mixin = {
|
|||
version: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
domain: string;
|
||||
scheme: string;
|
||||
wsScheme: string;
|
||||
apiUrl: string;
|
||||
|
|
|
@ -345,7 +345,7 @@ export default hasConfig
|
|||
userHost:
|
||||
note.userHost !== ""
|
||||
? note.userHost
|
||||
: url.parse(config.host).host,
|
||||
: config.domain,
|
||||
channelId: note.channelId ? note.channelId : "",
|
||||
mediaAttachment: attachmentType,
|
||||
userName: note.user?.username ?? "UNKNOWN",
|
||||
|
|
|
@ -5,12 +5,12 @@ import { toASCII } from "punycode";
|
|||
export function getFullApAccount(username: string, host: string | null) {
|
||||
return host
|
||||
? `${username}@${toPuny(host)}`
|
||||
: `${username}@${toPuny(config.host)}`;
|
||||
: `${username}@${toPuny(config.domain)}`;
|
||||
}
|
||||
|
||||
export function isSelfHost(host: string) {
|
||||
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) {
|
||||
|
|
|
@ -170,10 +170,4 @@ export class Instance {
|
|||
nullable: true,
|
||||
})
|
||||
public infoUpdatedAt: Date | null;
|
||||
|
||||
@Column("varchar", {
|
||||
length: 128,
|
||||
comment: "Domain for account ATs",
|
||||
})
|
||||
public accountDomain: string | null;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ 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,
|
||||
|
|
|
@ -21,12 +21,6 @@ export const packedFederationInstanceSchema = {
|
|||
nullable: false,
|
||||
example: "iceshrimp.example.com",
|
||||
},
|
||||
accountDomain: {
|
||||
type: "string",
|
||||
optional: true,
|
||||
nullable: true,
|
||||
example: "example.com",
|
||||
},
|
||||
usersCount: {
|
||||
type: "number",
|
||||
optional: false,
|
||||
|
|
|
@ -46,6 +46,7 @@ export async function checkFetch(req: IncomingMessage): Promise<number> {
|
|||
if (
|
||||
meta.privateMode &&
|
||||
host !== config.host &&
|
||||
host !== config.domain &&
|
||||
!meta.allowedHosts.includes(host)
|
||||
) {
|
||||
return 403;
|
||||
|
|
|
@ -108,6 +108,7 @@ export default class Resolver {
|
|||
if (
|
||||
meta.privateMode &&
|
||||
config.host !== host &&
|
||||
config.domain !== host &&
|
||||
!meta.allowedHosts.includes(host)
|
||||
) {
|
||||
throw new Error("Instance is not allowed");
|
||||
|
|
|
@ -36,7 +36,7 @@ export async function resolveUser(
|
|||
|
||||
// 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}`);
|
||||
return await Users.findOneBy({ usernameLower, host: IsNull() }).then(
|
||||
(u) => {
|
||||
|
|
|
@ -44,6 +44,13 @@ export const meta = {
|
|||
format: "url",
|
||||
example: "https://iceshrimp.example.com",
|
||||
},
|
||||
domain: {
|
||||
type: "string",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
format: "domain",
|
||||
example: "example.com",
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
optional: false,
|
||||
|
@ -411,6 +418,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
|
||||
name: instance.name,
|
||||
uri: config.url,
|
||||
domain: config.domain,
|
||||
description: instance.description,
|
||||
langs: instance.langs,
|
||||
tosUrl: instance.ToSUrl,
|
||||
|
|
|
@ -18,7 +18,6 @@ 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",
|
||||
|
|
|
@ -112,7 +112,7 @@ router.get("/avatar/@:acct", async (ctx) => {
|
|||
const user = await Users.findOne({
|
||||
where: {
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: host == null || host === config.host ? IsNull() : host,
|
||||
host: host == null || host === config.host || host === config.domain ? IsNull() : host,
|
||||
isSuspended: false,
|
||||
},
|
||||
relations: ["avatar"],
|
||||
|
|
|
@ -14,7 +14,7 @@ export default async function (
|
|||
) {
|
||||
const author = {
|
||||
link: `${config.url}/@${user.username}`,
|
||||
email: `${user.username}@${config.host}`,
|
||||
email: `${user.username}@${config.domain}`,
|
||||
name: user.name || user.username,
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ export default async function (
|
|||
|
||||
const feed = new Feed({
|
||||
id: author.link,
|
||||
title: `${author.name} (@${user.username}@${config.host})`,
|
||||
title: `${author.name} (@${user.username}@${config.domain})`,
|
||||
updated: notes[0].createdAt,
|
||||
generator: "Iceshrimp",
|
||||
description: `${user.notesCount} Notes, ${
|
||||
|
|
|
@ -120,7 +120,7 @@ router.get(webFingerPath, async (ctx) => {
|
|||
);
|
||||
|
||||
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,
|
||||
host: IsNull(),
|
||||
|
@ -147,7 +147,7 @@ router.get(webFingerPath, async (ctx) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const subject = `acct:${user.username}@${config.host}`;
|
||||
const subject = `acct:${user.username}@${config.domain}`;
|
||||
const self = {
|
||||
rel: "self",
|
||||
type: "application/activity+json",
|
||||
|
|
|
@ -59,7 +59,7 @@ export async function sendEmail(
|
|||
</footer>
|
||||
</main>
|
||||
<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>
|
||||
</body>
|
||||
</html>`,
|
||||
|
|
|
@ -180,7 +180,7 @@ function checkForSplash() {
|
|||
|
||||
fetchInstanceMetaPromise.then(() => {
|
||||
localStorage.setItem("v", instance.version);
|
||||
setHost(new URL(instance.uri).host);
|
||||
setHost(instance.domain);
|
||||
|
||||
// Init service worker
|
||||
initializeSw();
|
||||
|
|
|
@ -527,7 +527,7 @@ namespace MisskeyAPI {
|
|||
meta = (m: Entity.Meta, s: Entity.Stats): MegalodonEntity.Instance => {
|
||||
const wss = m.uri.replace(/^https:\/\//, "wss://");
|
||||
return {
|
||||
uri: m.uri,
|
||||
uri: m.domain,
|
||||
title: m.name,
|
||||
description: m.description,
|
||||
email: m.maintainerEmail,
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace MisskeyEntity {
|
|||
name: string
|
||||
version: string
|
||||
uri: string
|
||||
domain: string
|
||||
description: string
|
||||
langs: Array<string>
|
||||
disableRegistration: boolean
|
||||
|
|
Loading…
Reference in a new issue