mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): 🏷️ Replace API types with those from @lysand-org/client
This commit is contained in:
parent
99b8c35f7b
commit
106e34848a
81 changed files with 171 additions and 690 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import { proxyUrl } from "@/response";
|
||||
import type {
|
||||
AsyncAttachment as ApiAsyncAttachment,
|
||||
Attachment as ApiAttachment,
|
||||
} from "@lysand-org/client/types";
|
||||
import type { ContentFormat } from "@lysand-org/federation/types";
|
||||
import { config } from "config-manager";
|
||||
import { MediaBackendType } from "config-manager/config.type";
|
||||
|
|
@ -12,8 +16,6 @@ import {
|
|||
} from "drizzle-orm";
|
||||
import { db } from "~/drizzle/db";
|
||||
import { Attachments } from "~/drizzle/schema";
|
||||
import type { AsyncAttachment as APIAsyncAttachment } from "~/types/mastodon/async_attachment";
|
||||
import type { Attachment as APIAttachment } from "~/types/mastodon/attachment";
|
||||
import { BaseInterface } from "./base";
|
||||
|
||||
export type AttachmentType = InferSelectModel<typeof Attachments>;
|
||||
|
|
@ -136,7 +138,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
|
|||
return "";
|
||||
}
|
||||
|
||||
public getMastodonType(): APIAttachment["type"] {
|
||||
public getMastodonType(): ApiAttachment["type"] {
|
||||
if (this.data.mimeType.startsWith("image/")) {
|
||||
return "image";
|
||||
}
|
||||
|
|
@ -150,7 +152,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
public toApiMeta(): APIAttachment["meta"] {
|
||||
public toApiMeta(): ApiAttachment["meta"] {
|
||||
return {
|
||||
width: this.data.width || undefined,
|
||||
height: this.data.height || undefined,
|
||||
|
|
@ -181,7 +183,7 @@ export class Attachment extends BaseInterface<typeof Attachments> {
|
|||
};
|
||||
}
|
||||
|
||||
public toApi(): APIAttachment | APIAsyncAttachment {
|
||||
public toApi(): ApiAttachment | ApiAsyncAttachment {
|
||||
return {
|
||||
id: this.data.id,
|
||||
type: this.getMastodonType(),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { proxyUrl } from "@/response";
|
||||
import type { Emoji as ApiEmoji } from "@lysand-org/client/types";
|
||||
import type { CustomEmojiExtension } from "@lysand-org/federation/types";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
|
|
@ -12,7 +13,6 @@ import type { EmojiWithInstance } from "~/classes/functions/emoji";
|
|||
import { addInstanceIfNotExists } from "~/classes/functions/instance";
|
||||
import { db } from "~/drizzle/db";
|
||||
import { Emojis, Instances } from "~/drizzle/schema";
|
||||
import type { Emoji as APIEmoji } from "~/types/mastodon/emoji";
|
||||
import { BaseInterface } from "./base";
|
||||
|
||||
export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
|
||||
|
|
@ -152,7 +152,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
|
|||
return this.data.id;
|
||||
}
|
||||
|
||||
public toApi(): APIEmoji {
|
||||
public toApi(): ApiEmoji {
|
||||
return {
|
||||
// @ts-expect-error ID is not in regular Mastodon API
|
||||
id: this.id,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ import { idValidator } from "@/api";
|
|||
import { proxyUrl } from "@/response";
|
||||
import { sanitizedHtmlStrip } from "@/sanitization";
|
||||
import { getLogger } from "@logtape/logtape";
|
||||
import type {
|
||||
Attachment as ApiAttachment,
|
||||
Status as ApiStatus,
|
||||
} from "@lysand-org/client/types";
|
||||
import { EntityValidator } from "@lysand-org/federation";
|
||||
import type {
|
||||
ContentFormat,
|
||||
|
|
@ -42,8 +46,6 @@ import {
|
|||
Users,
|
||||
} from "~/drizzle/schema";
|
||||
import { config } from "~/packages/config-manager";
|
||||
import type { Attachment as apiAttachment } from "~/types/mastodon/attachment";
|
||||
import type { Status as APIStatus } from "~/types/mastodon/status";
|
||||
import { Attachment } from "./attachment";
|
||||
import { BaseInterface } from "./base";
|
||||
import { Emoji } from "./emoji";
|
||||
|
|
@ -306,7 +308,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
static async fromData(data: {
|
||||
author: User;
|
||||
content: ContentFormat;
|
||||
visibility: APIStatus["visibility"];
|
||||
visibility: ApiStatus["visibility"];
|
||||
isSensitive: boolean;
|
||||
spoilerText: string;
|
||||
emojis?: Emoji[];
|
||||
|
|
@ -396,7 +398,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
async updateFromData(data: {
|
||||
author?: User;
|
||||
content?: ContentFormat;
|
||||
visibility?: APIStatus["visibility"];
|
||||
visibility?: ApiStatus["visibility"];
|
||||
isSensitive?: boolean;
|
||||
spoilerText?: string;
|
||||
emojis?: Emoji[];
|
||||
|
|
@ -659,7 +661,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
content: "",
|
||||
},
|
||||
},
|
||||
visibility: note.visibility as APIStatus["visibility"],
|
||||
visibility: note.visibility as ApiStatus["visibility"],
|
||||
isSensitive: note.is_sensitive ?? false,
|
||||
spoilerText: note.subject ?? "",
|
||||
emojis,
|
||||
|
|
@ -755,7 +757,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
* @param userFetching - The user fetching the note (used to check if the note is favourite and such)
|
||||
* @returns The note in the Mastodon API format
|
||||
*/
|
||||
async toApi(userFetching?: User | null): Promise<APIStatus> {
|
||||
async toApi(userFetching?: User | null): Promise<ApiStatus> {
|
||||
const data = this.data;
|
||||
|
||||
// Convert mentions of local users from @username@host to @username
|
||||
|
|
@ -804,7 +806,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
favourited: data.liked,
|
||||
favourites_count: data.likeCount,
|
||||
media_attachments: (data.attachments ?? []).map(
|
||||
(a) => new Attachment(a).toApi() as apiAttachment,
|
||||
(a) => new Attachment(a).toApi() as ApiAttachment,
|
||||
),
|
||||
mentions: data.mentions.map((mention) => ({
|
||||
id: mention.id,
|
||||
|
|
@ -833,16 +835,19 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
spoiler_text: data.spoilerText,
|
||||
tags: [],
|
||||
uri: data.uri || this.getUri(),
|
||||
visibility: data.visibility as APIStatus["visibility"],
|
||||
visibility: data.visibility as ApiStatus["visibility"],
|
||||
url: data.uri || this.getMastoUri(),
|
||||
bookmarked: false,
|
||||
// @ts-expect-error Glitch-SOC extension
|
||||
quote: data.quotingId
|
||||
? (await Note.fromId(data.quotingId, userFetching?.id).then(
|
||||
(n) => n?.toApi(userFetching),
|
||||
)) ?? null
|
||||
: null,
|
||||
quote_id: data.quotingId || undefined,
|
||||
edited_at: data.updatedAt
|
||||
? new Date(data.updatedAt).toISOString()
|
||||
: null,
|
||||
emoji_reactions: [],
|
||||
plain_content: data.contentSource,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { proxyUrl } from "@/response";
|
||||
import type { RolePermission } from "@lysand-org/client/types";
|
||||
import { config } from "config-manager";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
|
|
@ -181,7 +182,7 @@ export class Role extends BaseInterface<typeof Roles> {
|
|||
return {
|
||||
id: this.id,
|
||||
name: this.data.name,
|
||||
permissions: this.data.permissions,
|
||||
permissions: this.data.permissions as unknown as RolePermission[],
|
||||
priority: this.data.priority,
|
||||
description: this.data.description,
|
||||
visible: this.data.visible,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ import { getBestContentType, urlToContentFormat } from "@/content_types";
|
|||
import { randomString } from "@/math";
|
||||
import { addUserToMeilisearch } from "@/meilisearch";
|
||||
import { proxyUrl } from "@/response";
|
||||
import type {
|
||||
Account as ApiAccount,
|
||||
Mention as ApiMention,
|
||||
} from "@lysand-org/client/types";
|
||||
import { EntityValidator } from "@lysand-org/federation";
|
||||
import type { Entity, User as LysandUser } from "@lysand-org/federation/types";
|
||||
import {
|
||||
|
|
@ -38,8 +42,6 @@ import {
|
|||
Users,
|
||||
} from "~/drizzle/schema";
|
||||
import { type Config, config } from "~/packages/config-manager";
|
||||
import type { Account as apiAccount } from "~/types/mastodon/account";
|
||||
import type { Mention as apiMention } from "~/types/mastodon/mention";
|
||||
import { BaseInterface } from "./base";
|
||||
import { Emoji } from "./emoji";
|
||||
import type { Note } from "./note";
|
||||
|
|
@ -558,7 +560,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
}
|
||||
}
|
||||
|
||||
toApi(isOwnAccount = false): apiAccount {
|
||||
toApi(isOwnAccount = false): ApiAccount {
|
||||
const user = this.data;
|
||||
return {
|
||||
id: user.id,
|
||||
|
|
@ -698,7 +700,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
};
|
||||
}
|
||||
|
||||
toMention(): apiMention {
|
||||
toMention(): ApiMention {
|
||||
return {
|
||||
url: this.getUri(),
|
||||
username: this.data.username,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue