mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-25 02:09:05 +01:00
Finish up support for local split domain configurations
This commit is contained in:
parent
c6dee2da09
commit
84867f1c13
@ -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),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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")]
|
#[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")]
|
||||||
|
@ -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,
|
||||||
);
|
);
|
||||||
|
@ -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}`;
|
||||||
|
@ -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;
|
||||||
|
@ -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",
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
@ -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");
|
||||||
|
@ -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) => {
|
||||||
|
@ -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,
|
||||||
|
@ -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",
|
||||||
|
@ -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"],
|
||||||
|
@ -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, ${
|
||||||
|
@ -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",
|
||||||
|
@ -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>`,
|
||||||
|
@ -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();
|
||||||
|
@ -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,
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user