mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(federation): ♻️ Move Versia Note URIs to /notes, instead of /objects
This commit is contained in:
parent
4063d58d79
commit
6622ee9020
7 changed files with 358 additions and 36 deletions
|
|
@ -19,7 +19,6 @@ import {
|
|||
} from "drizzle-orm";
|
||||
import { config } from "~/config.ts";
|
||||
import { BaseInterface } from "./base.ts";
|
||||
import { Note } from "./note.ts";
|
||||
import { User } from "./user.ts";
|
||||
|
||||
type LikeType = InferSelectModel<typeof Likes> & {
|
||||
|
|
@ -172,12 +171,9 @@ export class Like extends BaseInterface<typeof Likes, LikeType> {
|
|||
type: "pub.versia:likes/Like",
|
||||
created_at: new Date(this.data.createdAt).toISOString(),
|
||||
liked:
|
||||
Note.getUri(
|
||||
this.data.liked.id,
|
||||
this.data.liked.uri
|
||||
? new URL(this.data.liked.uri)
|
||||
: undefined,
|
||||
)?.toString() ?? "",
|
||||
this.data.liked.uri ??
|
||||
new URL(`/notes/${this.data.liked.id}`, config.http.base_url)
|
||||
.href,
|
||||
uri: this.getUri().toString(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { idValidator } from "@/api";
|
||||
import { localObjectUri } from "@/constants";
|
||||
import { mergeAndDeduplicate } from "@/lib.ts";
|
||||
import { sanitizedHtmlStrip } from "@/sanitization";
|
||||
import { sentry } from "@/sentry";
|
||||
|
|
@ -858,14 +857,9 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
}
|
||||
|
||||
public getUri(): URL {
|
||||
return new URL(this.data.uri || localObjectUri(this.id));
|
||||
}
|
||||
|
||||
public static getUri(id: string | null, uri?: URL | null): URL | null {
|
||||
if (!id) {
|
||||
return null;
|
||||
}
|
||||
return uri || localObjectUri(id);
|
||||
return this.data.uri
|
||||
? new URL(this.data.uri)
|
||||
: new URL(`/notes/${this.id}`, config.http.base_url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -928,14 +922,16 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
mention.uri ? new URL(mention.uri) : null,
|
||||
).toString(),
|
||||
),
|
||||
quotes: Note.getUri(
|
||||
status.quotingId,
|
||||
status.quote?.uri ? new URL(status.quote.uri) : null,
|
||||
)?.toString(),
|
||||
replies_to: Note.getUri(
|
||||
status.replyId,
|
||||
status.reply?.uri ? new URL(status.reply.uri) : null,
|
||||
)?.toString(),
|
||||
quotes: status.quote
|
||||
? (status.quote.uri ??
|
||||
new URL(`/notes/${status.quote.id}`, config.http.base_url)
|
||||
.href)
|
||||
: null,
|
||||
replies_to: status.reply
|
||||
? (status.reply.uri ??
|
||||
new URL(`/notes/${status.reply.id}`, config.http.base_url)
|
||||
.href)
|
||||
: null,
|
||||
subject: status.spoilerText,
|
||||
// TODO: Refactor as part of groups
|
||||
group: status.visibility === "public" ? "public" : "followers",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { ReactionExtension } from "@versia/federation/types";
|
||||
import { Emoji, Instance, Note, User, db } from "@versia/kit/db";
|
||||
import { Emoji, Instance, type Note, User, db } from "@versia/kit/db";
|
||||
import { type Notes, Reactions, type Users } from "@versia/kit/tables";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
|
|
@ -159,7 +159,7 @@ export class Reaction extends BaseInterface<typeof Reactions, ReactionType> {
|
|||
return this.data.uri
|
||||
? new URL(this.data.uri)
|
||||
: new URL(
|
||||
`/objects/${this.data.noteId}/reactions/${this.id}`,
|
||||
`/notes/${this.data.noteId}/reactions/${this.id}`,
|
||||
baseUrl,
|
||||
);
|
||||
}
|
||||
|
|
@ -187,12 +187,9 @@ export class Reaction extends BaseInterface<typeof Reactions, ReactionType> {
|
|||
created_at: new Date(this.data.createdAt).toISOString(),
|
||||
id: this.id,
|
||||
object:
|
||||
Note.getUri(
|
||||
this.data.note.id,
|
||||
this.data.note.uri
|
||||
? new URL(this.data.note.uri)
|
||||
: undefined,
|
||||
)?.toString() ?? "",
|
||||
this.data.note.uri ??
|
||||
new URL(`/notes/${this.data.noteId}`, config.http.base_url)
|
||||
.href,
|
||||
content: this.hasCustomEmoji()
|
||||
? `:${this.data.emoji?.shortcode}:`
|
||||
: this.data.emojiText || "",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue