mirror of
https://github.com/versia-pub/server.git
synced 2026-04-27 20:59:15 +02:00
refactor(database): Remove unused columns and rename baseUrl to domain
This commit is contained in:
parent
35d285bb2a
commit
df2a5ce260
16 changed files with 2448 additions and 59 deletions
|
|
@ -274,7 +274,7 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
|
||||
public static async resolve(domain: string): Promise<Instance> {
|
||||
const existingInstance = await Instance.fromSql(
|
||||
eq(Instances.baseUrl, domain),
|
||||
eq(Instances.domain, domain),
|
||||
);
|
||||
|
||||
if (existingInstance) {
|
||||
|
|
@ -287,7 +287,7 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
|
||||
return Instance.insert({
|
||||
id: randomUUIDv7(),
|
||||
baseUrl: domain,
|
||||
domain,
|
||||
name: metadata.data.name,
|
||||
version: metadata.data.software.version,
|
||||
logo: metadata.data.logo,
|
||||
|
|
@ -298,11 +298,11 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
}
|
||||
|
||||
public async updateFromRemote(): Promise<Instance> {
|
||||
const output = await Instance.fetchMetadata(this.data.baseUrl);
|
||||
const output = await Instance.fetchMetadata(this.data.domain);
|
||||
|
||||
if (!output) {
|
||||
federationResolversLogger.error`Failed to update instance ${chalk.bold(
|
||||
this.data.baseUrl,
|
||||
this.data.domain,
|
||||
)}`;
|
||||
throw new Error("Failed to update instance");
|
||||
}
|
||||
|
|
@ -353,7 +353,7 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
!this.data.extensions?.["pub.versia:instance_messaging"]?.endpoint
|
||||
) {
|
||||
federationMessagingLogger.info`Instance ${chalk.gray(
|
||||
this.data.baseUrl,
|
||||
this.data.domain,
|
||||
)} does not support Instance Messaging, skipping message`;
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { config } from "@versia-server/config";
|
||||
import {
|
||||
and,
|
||||
desc,
|
||||
|
|
@ -161,15 +160,11 @@ export class Like extends BaseInterface<typeof Likes, LikeType> {
|
|||
);
|
||||
}
|
||||
|
||||
public getUri(): URL {
|
||||
return new URL(`/likes/${this.data.id}`, config.http.base_url);
|
||||
}
|
||||
|
||||
public toVersia(): VersiaEntities.Like {
|
||||
let likedReference = this.data.liked.id;
|
||||
|
||||
if (this.data.liked.author.instance) {
|
||||
likedReference = `${this.data.liked.author.instance.baseUrl}:${this.data.liked.remoteId}`;
|
||||
likedReference = `${this.data.liked.author.instance.domain}:${this.data.liked.remoteId}`;
|
||||
}
|
||||
|
||||
return new VersiaEntities.Like({
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
public get reference(): VersiaEntities.Reference {
|
||||
if (this.remote) {
|
||||
const instanceUrl = new URL(
|
||||
this.author.data.instance?.baseUrl || "",
|
||||
this.author.data.instance?.domain || "",
|
||||
);
|
||||
return new VersiaEntities.Reference(this.id, instanceUrl.hostname);
|
||||
}
|
||||
|
|
@ -978,7 +978,7 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
? reference
|
||||
: new VersiaEntities.Reference(
|
||||
reference.id,
|
||||
instance.data.baseUrl,
|
||||
instance.data.domain,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -1232,11 +1232,11 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
acct: User.getAcct(
|
||||
mention.instanceId === null,
|
||||
mention.username,
|
||||
mention.instance?.baseUrl,
|
||||
mention.instance?.domain,
|
||||
),
|
||||
url: new URL(
|
||||
`/@${mention.username}${
|
||||
mention.instance ? `@${mention.instance.baseUrl}` : ""
|
||||
mention.instance ? `@${mention.instance.domain}` : ""
|
||||
}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
|
|
@ -1274,8 +1274,8 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
}
|
||||
|
||||
public getUri(): URL {
|
||||
const domain = this.author.data.instance?.baseUrl
|
||||
? new URL(`https://${this.author.data.instance.baseUrl}`)
|
||||
const domain = this.author.data.instance?.domain
|
||||
? new URL(`https://${this.author.data.instance.domain}`)
|
||||
: config.http.base_url;
|
||||
|
||||
return new URL(
|
||||
|
|
@ -1315,13 +1315,13 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
let quoteReference = status.quote?.id ?? null;
|
||||
|
||||
if (quoteReference && status.quote?.author.instance) {
|
||||
quoteReference = `${status.quote.author.instance.baseUrl}:${status.quote.remoteId}`;
|
||||
quoteReference = `${status.quote.author.instance.domain}:${status.quote.remoteId}`;
|
||||
}
|
||||
|
||||
let replyReference = status.reply?.id ?? null;
|
||||
|
||||
if (replyReference && status.reply?.author.instance) {
|
||||
replyReference = `${status.reply.author.instance.baseUrl}:${status.reply.remoteId}`;
|
||||
replyReference = `${status.reply.author.instance.domain}:${status.reply.remoteId}`;
|
||||
}
|
||||
|
||||
return new VersiaEntities.Note({
|
||||
|
|
@ -1349,7 +1349,7 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
is_sensitive: status.sensitive,
|
||||
mentions: status.mentions.map((mention) =>
|
||||
mention.instance
|
||||
? `${mention.instance.baseUrl}:${mention.id}`
|
||||
? `${mention.instance.domain}:${mention.id}`
|
||||
: mention.id,
|
||||
),
|
||||
quotes: quoteReference,
|
||||
|
|
@ -1379,7 +1379,7 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
id: this.id,
|
||||
created_at: new Date().toISOString(),
|
||||
shared: this.data.reblog.author.instance
|
||||
? `${this.data.reblog.author.instance.baseUrl}:${this.data.reblog.id}`
|
||||
? `${this.data.reblog.author.instance.domain}:${this.data.reblog.id}`
|
||||
: this.data.reblog.id,
|
||||
});
|
||||
}
|
||||
|
|
@ -1499,7 +1499,7 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
} else if (reaction.emoji?.instance === null) {
|
||||
emojiName = `:${reaction.emoji.shortcode}:`;
|
||||
} else if (reaction.emoji?.instance) {
|
||||
emojiName = `:${reaction.emoji.shortcode}@${reaction.emoji.instance.baseUrl}:`;
|
||||
emojiName = `:${reaction.emoji.shortcode}@${reaction.emoji.instance.domain}:`;
|
||||
} else {
|
||||
continue; // Skip invalid reactions
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { config } from "@versia-server/config";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import {
|
||||
and,
|
||||
|
|
@ -212,13 +213,17 @@ export class Reaction extends BaseInterface<typeof Reactions, ReactionType> {
|
|||
);
|
||||
}
|
||||
|
||||
public getUri(baseUrl: URL): URL {
|
||||
return this.data.uri
|
||||
? new URL(this.data.uri)
|
||||
: new URL(
|
||||
`/notes/${this.data.noteId}/reactions/${this.id}`,
|
||||
baseUrl,
|
||||
);
|
||||
public getUri(): URL {
|
||||
const domain = this.data.note.author.instance?.domain
|
||||
? new URL(`https://${this.data.note.author.instance.domain}`)
|
||||
: config.http.base_url;
|
||||
|
||||
return new URL(
|
||||
`/.versia/v0.6/entities/${encodeURIComponent(
|
||||
"pub.versia:reactions/Reaction",
|
||||
)}/${this.id}`,
|
||||
domain,
|
||||
);
|
||||
}
|
||||
|
||||
public get local(): boolean {
|
||||
|
|
@ -237,7 +242,7 @@ export class Reaction extends BaseInterface<typeof Reactions, ReactionType> {
|
|||
let noteReference = this.data.note.id;
|
||||
|
||||
if (this.data.note.author.instance) {
|
||||
noteReference = `${this.data.note.author.instance.baseUrl}:${this.data.note.remoteId}`;
|
||||
noteReference = `${this.data.note.author.instance.domain}:${this.data.note.remoteId}`;
|
||||
}
|
||||
|
||||
return new VersiaEntities.Reaction({
|
||||
|
|
|
|||
|
|
@ -229,13 +229,13 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
|
||||
return new VersiaEntities.Reference(
|
||||
this.data.remoteId as string,
|
||||
(this.data.instance as typeof Instance.$type).baseUrl,
|
||||
(this.data.instance as typeof Instance.$type).domain,
|
||||
);
|
||||
}
|
||||
|
||||
public get uri(): URL {
|
||||
const domain = this.data.instance?.baseUrl
|
||||
? new URL(`https://${this.data.instance.baseUrl}`)
|
||||
const domain = this.data.instance?.domain
|
||||
? new URL(`https://${this.data.instance.domain}`)
|
||||
: config.http.base_url;
|
||||
|
||||
return new URL(
|
||||
|
|
@ -335,7 +335,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
author: this.id,
|
||||
created_at: new Date().toISOString(),
|
||||
followee: followee.data.instance
|
||||
? `${followee.data.instance.baseUrl}:${followee.id}`
|
||||
? `${followee.data.instance.domain}:${followee.id}`
|
||||
: followee.id,
|
||||
});
|
||||
}
|
||||
|
|
@ -357,7 +357,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
author: this.id,
|
||||
created_at: new Date().toISOString(),
|
||||
follower: follower.data.instance
|
||||
? `${follower.data.instance.baseUrl}:${follower.id}`
|
||||
? `${follower.data.instance.domain}:${follower.id}`
|
||||
: follower.id,
|
||||
});
|
||||
|
||||
|
|
@ -382,7 +382,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
author: this.id,
|
||||
created_at: new Date().toISOString(),
|
||||
follower: follower.data.instance
|
||||
? `${follower.data.instance.baseUrl}:${follower.id}`
|
||||
? `${follower.data.instance.domain}:${follower.id}`
|
||||
: follower.id,
|
||||
});
|
||||
|
||||
|
|
@ -840,7 +840,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
? reference
|
||||
: new VersiaEntities.Reference(
|
||||
reference.id,
|
||||
instance.data.baseUrl,
|
||||
instance.data.domain,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -910,7 +910,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
public getAcct(): string {
|
||||
return this.local
|
||||
? this.data.username
|
||||
: `${this.data.username}@${this.data.instance?.baseUrl}`;
|
||||
: `${this.data.username}@${this.data.instance?.domain}`;
|
||||
}
|
||||
|
||||
public static getAcct(
|
||||
|
|
@ -1008,7 +1008,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
|
||||
try {
|
||||
await Instance.federationRequester.postEntity(
|
||||
user.data.instance.baseUrl,
|
||||
user.data.instance.domain,
|
||||
entity,
|
||||
);
|
||||
} catch (e) {
|
||||
|
|
@ -1034,7 +1034,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
uri: this.uri.href,
|
||||
url: new URL(
|
||||
`/@${user.username}${
|
||||
user.instanceId ? `@${user.instance?.baseUrl}` : ""
|
||||
user.instanceId ? `@${user.instance?.domain}` : ""
|
||||
}`,
|
||||
config.http.base_url,
|
||||
).href,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue