From 6606eda98165107928eca172e6737f3d3446aa57 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 13 Sep 2023 23:16:31 +0200 Subject: [PATCH] [mastodon-client] GET /statuses/:id --- packages/backend/src/misc/populate-emojis.ts | 2 +- packages/backend/src/server/api/index.ts | 4 +- .../server/api/mastodon/converters/emoji.ts | 13 ++ .../server/api/mastodon/converters/file.ts | 36 ++++++ .../server/api/mastodon/converters/mention.ts | 17 +++ .../src/server/api/mastodon/converters/mfm.ts | 8 ++ .../server/api/mastodon/converters/note.ts | 111 ++++++++++++++++++ .../server/api/mastodon/converters/poll.ts | 37 ++++++ .../server/api/mastodon/converters/user.ts | 55 +++++++++ .../api/mastodon/converters/visibility.ts | 32 +++++ .../server/api/mastodon/endpoints/status.ts | 29 +++-- .../server/api/mastodon/entities/account.ts | 27 +++++ .../server/api/mastodon/entities/activity.ts | 8 ++ .../api/mastodon/entities/announcement.ts | 34 ++++++ .../api/mastodon/entities/application.ts | 7 ++ .../api/mastodon/entities/async_attachment.ts | 14 +++ .../api/mastodon/entities/attachment.ts | 49 ++++++++ .../src/server/api/mastodon/entities/card.ts | 16 +++ .../server/api/mastodon/entities/context.ts | 8 ++ .../api/mastodon/entities/conversation.ts | 11 ++ .../src/server/api/mastodon/entities/emoji.ts | 9 ++ .../api/mastodon/entities/featured_tag.ts | 8 ++ .../src/server/api/mastodon/entities/field.ts | 7 ++ .../server/api/mastodon/entities/filter.ts | 12 ++ .../server/api/mastodon/entities/history.ts | 7 ++ .../api/mastodon/entities/identity_proof.ts | 9 ++ .../server/api/mastodon/entities/instance.ts | 41 +++++++ .../src/server/api/mastodon/entities/list.ts | 6 + .../server/api/mastodon/entities/marker.ts | 15 +++ .../server/api/mastodon/entities/mention.ts | 8 ++ .../api/mastodon/entities/notification.ts | 15 +++ .../src/server/api/mastodon/entities/poll.ts | 14 +++ .../api/mastodon/entities/poll_option.ts | 6 + .../api/mastodon/entities/preferences.ts | 9 ++ .../mastodon/entities/push_subscription.ts | 16 +++ .../server/api/mastodon/entities/reaction.ts | 12 ++ .../api/mastodon/entities/relationship.ts | 17 +++ .../server/api/mastodon/entities/report.ts | 9 ++ .../server/api/mastodon/entities/results.ts | 11 ++ .../api/mastodon/entities/scheduled_status.ts | 10 ++ .../server/api/mastodon/entities/source.ts | 10 ++ .../src/server/api/mastodon/entities/stats.ts | 7 ++ .../server/api/mastodon/entities/status.ts | 45 +++++++ .../api/mastodon/entities/status_edit.ts | 23 ++++ .../api/mastodon/entities/status_params.ts | 12 ++ .../src/server/api/mastodon/entities/tag.ts | 10 ++ .../src/server/api/mastodon/entities/token.ts | 8 ++ .../src/server/api/mastodon/entities/urls.ts | 5 + .../backend/src/server/api/mastodon/entity.ts | 38 ++++++ 49 files changed, 907 insertions(+), 10 deletions(-) create mode 100644 packages/backend/src/server/api/mastodon/converters/emoji.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/file.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/mention.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/mfm.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/note.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/poll.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/user.ts create mode 100644 packages/backend/src/server/api/mastodon/converters/visibility.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/account.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/activity.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/announcement.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/application.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/async_attachment.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/attachment.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/card.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/context.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/conversation.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/emoji.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/featured_tag.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/field.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/filter.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/history.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/identity_proof.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/instance.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/list.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/marker.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/mention.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/notification.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/poll.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/poll_option.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/preferences.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/push_subscription.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/reaction.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/relationship.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/report.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/results.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/scheduled_status.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/source.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/stats.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/status.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/status_edit.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/status_params.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/tag.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/token.ts create mode 100644 packages/backend/src/server/api/mastodon/entities/urls.ts create mode 100644 packages/backend/src/server/api/mastodon/entity.ts diff --git a/packages/backend/src/misc/populate-emojis.ts b/packages/backend/src/misc/populate-emojis.ts index 795a267f9..870dff5cf 100644 --- a/packages/backend/src/misc/populate-emojis.ts +++ b/packages/backend/src/misc/populate-emojis.ts @@ -14,7 +14,7 @@ const cache = new Cache("populateEmojis", 60 * 60 * 12); /** * 添付用絵文字情報 */ -type PopulatedEmoji = { +export type PopulatedEmoji = { name: string; url: string; width: number | null; diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 766c02b37..fe0b6a4d7 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -91,7 +91,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => { return; } const data = await client.uploadMedia(multipartData); - ctx.body = convertAttachment(data.data as Entity.Attachment); + ctx.body = convertAttachment(data.data as MastodonEntity.Attachment); } catch (e: any) { console.error(e); ctx.status = 401; @@ -110,7 +110,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => { return; } const data = await client.uploadMedia(multipartData, ctx.request.body); - ctx.body = convertAttachment(data.data as Entity.Attachment); + ctx.body = convertAttachment(data.data as MastodonEntity.Attachment); } catch (e: any) { console.error(e); ctx.status = 401; diff --git a/packages/backend/src/server/api/mastodon/converters/emoji.ts b/packages/backend/src/server/api/mastodon/converters/emoji.ts new file mode 100644 index 000000000..2f79aaafa --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/emoji.ts @@ -0,0 +1,13 @@ +import { PopulatedEmoji } from "@/misc/populate-emojis.js"; + +export class EmojiConverter { + public static encode(e: PopulatedEmoji) { + return { + shortcode: e.name, + static_url: e.url, + url: e.url, + visible_in_picker: true, + category: "unknown", //FIXME - e.category + }; + } +} diff --git a/packages/backend/src/server/api/mastodon/converters/file.ts b/packages/backend/src/server/api/mastodon/converters/file.ts new file mode 100644 index 000000000..eb4caf7cc --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/file.ts @@ -0,0 +1,36 @@ +import { Packed } from "@/misc/schema.js"; + +export class FileConverter { + public static encode(f: Packed<"DriveFile">): MastodonEntity.Attachment { + return { + id: f.id, + type: this.encodefileType(f.type), + url: f.url ?? "", + remote_url: f.url, + preview_url: f.thumbnailUrl, + text_url: f.url, + meta: { + width: f.properties.width, + height: f.properties.height, + }, + description: f.comment, + blurhash: f.blurhash, + }; + } + + private static encodefileType(s: string): "unknown" | "image" | "gifv" | "video" | "audio" { + if (s === "image/gif") { + return "gifv"; + } + if (s.includes("image")) { + return "image"; + } + if (s.includes("video")) { + return "video"; + } + if (s.includes("audio")) { + return "audio"; + } + return "unknown"; + }; +} diff --git a/packages/backend/src/server/api/mastodon/converters/mention.ts b/packages/backend/src/server/api/mastodon/converters/mention.ts new file mode 100644 index 000000000..edf200f79 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/mention.ts @@ -0,0 +1,17 @@ +import { User } from "@/models/entities/user.js"; +import config from "@/config/index.js"; + +export function convertMention(u: User): MastodonEntity.Mention { + let acct = u.username; + let acctUrl = `https://${u.host || config.host}/@${u.username}`; + if (u.host) { + acct = `${u.username}@${u.host}`; + acctUrl = `https://${u.host}/@${u.username}`; + } + return { + id: u.id, + username: u.username, + acct: acct, + url: u.uri ?? acctUrl, + }; +} diff --git a/packages/backend/src/server/api/mastodon/converters/mfm.ts b/packages/backend/src/server/api/mastodon/converters/mfm.ts new file mode 100644 index 000000000..f398829f2 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/mfm.ts @@ -0,0 +1,8 @@ +export const escapeMFM = (text: string): string => text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'") + .replace(/`/g, "`") + .replace(/\r?\n/g, "
"); diff --git a/packages/backend/src/server/api/mastodon/converters/note.ts b/packages/backend/src/server/api/mastodon/converters/note.ts new file mode 100644 index 000000000..b2d8940f6 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/note.ts @@ -0,0 +1,111 @@ +import { ILocalUser } from "@/models/entities/user.js"; +import {getNote, getUser} from "@/server/api/common/getters.js"; +import { Note } from "@/models/entities/note.js"; +import config from "@/config/index.js"; +import mfm from "mfm-js"; +import { toHtml } from "@/mfm/to-html.js"; +import { convertUser } from "@/server/api/mastodon/converters/user.js"; +import { Visibility } from "@/server/api/mastodon/converters/visibility.js"; +import { escapeMFM } from "@/server/api/mastodon/converters/mfm.js"; +import { populateEmojis } from "@/misc/populate-emojis.js"; +import { EmojiConverter } from "@/server/api/mastodon/converters/emoji.js"; +import { DriveFiles, NoteFavorites, NoteReactions, Notes, NoteThreadMutings } from "@/models/index.js"; +import { decodeReaction } from "@/misc/reaction-lib.js"; +import { convertMention } from "@/server/api/mastodon/converters/mention.js"; +import { PollConverter } from "@/server/api/mastodon/converters/poll.js"; +import { populatePoll } from "@/models/repositories/note.js"; +import { FileConverter } from "@/server/api/mastodon/converters/file.js"; + +export class NoteConverter { + public static async encode(note: Note, user: ILocalUser): Promise { + const noteUser = note.user ?? await getUser(note.userId); + + if (!await Notes.isVisibleForMe(note, user.id ?? null)) + throw new Error(); + + const host = note.user?.host ?? null; + + const reactionEmojiNames = Object.keys(note.reactions) + .filter((x) => x?.startsWith(":")) + .map((x) => decodeReaction(x).reaction) + .map((x) => x.replace(/:/g, "")); + + const noteEmoji = await populateEmojis( + note.emojis.concat(reactionEmojiNames), + host, + ); + + const reactionCount = await NoteReactions.countBy({id: note.id}); + + const reaction = user ? await NoteReactions.findOneBy({ + userId: user.id, + noteId: note.id, + }) : null; + + const isReblogged = user ? await Notes.exist({ + where: { + userId: user.id, + renoteId: note.id + } + }) : null; + + const reply = note.reply ?? (note.replyId ? await getNote(note.replyId, user) : null); + + const isBookmarked = await NoteFavorites.exist({ + where: { + userId: user.id, + noteId: note.id, + }, + take: 1, + }); + + const isMuted = await NoteThreadMutings.exist({ + where: { + userId: user.id, + threadId: note.threadId || note.id, + } + }); + + const files = await DriveFiles.packMany(note.fileIds); + + // FIXME use await-all + + return { + id: note.id, + uri: note.uri ? note.uri : `https://${config.host}/notes/${note.id}`, + url: note.uri ? note.uri : `https://${config.host}/notes/${note.id}`, + account: await convertUser(noteUser), + in_reply_to_id: note.replyId, + in_reply_to_account_id: reply?.userId ?? null, + reblog: note.renote ? await this.encode(note.renote, user) : null, + content: note.text ? toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers)) ?? escapeMFM(note.text) : "", + text: note.text ? note.text : null, + created_at: note.createdAt.toISOString(), + // Remove reaction emojis with names containing @ from the emojis list. + emojis: noteEmoji + .filter((e) => e.name.indexOf("@") === -1) + .map((e) => EmojiConverter.encode(e)), + replies_count: note.repliesCount, + reblogs_count: note.renoteCount, + favourites_count: reactionCount, + reblogged: isReblogged, + favourited: !!reaction, + muted: isMuted, + sensitive: files.length > 0 ? files.some((f) => f.isSensitive) : false, + spoiler_text: note.cw ? note.cw : "", + visibility: Visibility.encode(note.visibility), + media_attachments: files.length > 0 ? files.map((f) => FileConverter.encode(f)) : [], + mentions: await Promise.all(note.mentions.map(async p => convertMention(await getUser(p)))), + tags: [], //FIXME + card: null, //FIXME + poll: note.hasPoll ? PollConverter.encode(await populatePoll(note, user.id), note.id) : null, + application: null, //FIXME + language: null, //FIXME + pinned: null, //FIXME + // Use emojis list to provide URLs for emoji reactions. + reactions: [], //FIXME: this.mapReactions(n.emojis, n.reactions, n.myReaction), + bookmarked: isBookmarked, + quote: note.renote && note.text ? await this.encode(note.renote, user) : null, + }; + } +} diff --git a/packages/backend/src/server/api/mastodon/converters/poll.ts b/packages/backend/src/server/api/mastodon/converters/poll.ts new file mode 100644 index 000000000..4da0844a3 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/poll.ts @@ -0,0 +1,37 @@ +type Choice = { + text: string + votes: number + isVoted: boolean +} + +type Poll = { + multiple: boolean + expiresAt: Date | null + choices: Array +} + +export class PollConverter { + public static encode(p: Poll, noteId: string): MastodonEntity.Poll { + const now = new Date(); + const count = p.choices.reduce((sum, choice) => sum + choice.votes, 0); + return { + id: noteId, + expires_at: p.expiresAt?.toISOString() ?? null, + expired: p.expiresAt == null ? false : now > p.expiresAt, + multiple: p.multiple, + votes_count: count, + options: p.choices.map((c) => this.encodeChoice(c)), + voted: p.choices.some((c) => c.isVoted), + own_votes: p.choices + .filter((c) => c.isVoted) + .map((c) => p.choices.indexOf(c)), + }; + } + + private static encodeChoice(c: Choice): MastodonEntity.PollOption { + return { + title: c.text, + votes_count: c.votes, + }; + } +} diff --git a/packages/backend/src/server/api/mastodon/converters/user.ts b/packages/backend/src/server/api/mastodon/converters/user.ts new file mode 100644 index 000000000..38a24e14b --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/user.ts @@ -0,0 +1,55 @@ +import { User } from "@/models/entities/user.js"; +import config from "@/config/index.js"; +import { UserProfiles, Users } from "@/models/index.js"; +import { EmojiConverter } from "@/server/api/mastodon/converters/emoji.js"; +import { populateEmojis } from "@/misc/populate-emojis.js"; +import { toHtml } from "@/mfm/to-html.js"; +import { escapeMFM } from "@/server/api/mastodon/converters/mfm.js"; +import mfm from "mfm-js"; + +type Field = { + name: string; + value: string; + verified?: boolean; +}; + +export async function convertUser(u: User): Promise { + let acct = u.username; + let acctUrl = `https://${u.host || config.host}/@${u.username}`; + if (u.host) { + acct = `${u.username}@${u.host}`; + acctUrl = `https://${u.host}/@${u.username}`; + } + const profile = await UserProfiles.findOneBy({userId: u.id}); + const bio = toHtml(mfm.parse(profile?.description ?? "")) ?? escapeMFM(profile?.description ?? ""); + + return { + id: u.id, + username: u.username, + acct: acct, + display_name: u.name || u.username, + locked: u.isLocked, + created_at: new Date().toISOString(), + followers_count: u.followersCount, + following_count: u.followingCount, + statuses_count: u.notesCount, + note: bio, + url: u.uri ?? acctUrl, + avatar: u.avatar?.url ?? Users.getIdenticonUrl(u.id), + avatar_static: u.avatar?.url ?? Users.getIdenticonUrl(u.id), + header: u.banner?.url ?? `${config.url}/static-assets/transparent.png`, + header_static: u.banner?.url ?? `${config.url}/static-assets/transparent.png`, + emojis: (await populateEmojis(u.emojis, u.host)).map((e) => EmojiConverter.encode(e)), + moved: null, //FIXME + fields: profile?.fields.map(p => convertField(p)) ?? [], + bot: u.isBot + }; +} + +function convertField(f: Field): MastodonEntity.Field { + return { + name: f.name, + value: toHtml(mfm.parse(f.value)) ?? escapeMFM(f.value), + verified_at: f.verified ? (new Date()).toISOString() : null, + } +} diff --git a/packages/backend/src/server/api/mastodon/converters/visibility.ts b/packages/backend/src/server/api/mastodon/converters/visibility.ts new file mode 100644 index 000000000..6599d6cf7 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/converters/visibility.ts @@ -0,0 +1,32 @@ +type IceshrimpVisibility = "public" | "home" | "followers" | "specified" | "hidden"; +type MastodonVisibility = "public" | "unlisted" | "private" | "direct"; + +export class Visibility { + public static encode (v: IceshrimpVisibility): MastodonVisibility { + switch (v) { + case "public": + return v; + case "home": + return "unlisted"; + case "followers": + return "private"; + case "specified": + return "direct"; + case "hidden": + throw new Error(); + } + } + + public static decode(v: MastodonVisibility): IceshrimpVisibility { + switch (v) { + case "public": + return v; + case "unlisted": + return "home"; + case "private": + return "followers"; + case "direct": + return "specified"; + } + } +} diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 44c9f1936..4458a7a1f 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -12,6 +12,10 @@ import { convertPoll, convertStatus, } from "../converters.js"; +import {NoteConverter} from "@/server/api/mastodon/converters/note.js"; +import {getNote} from "@/server/api/common/getters.js"; +import authenticate from "@/server/api/authenticate.js"; +import {Notes} from "@/models"; function normalizeQuery(data: any) { const str = querystring.stringify(data); @@ -147,14 +151,25 @@ export function apiStatusMastodon(router: Router): void { } }); router.get<{ Params: { id: string } }>("/v1/statuses/:id", async (ctx) => { - const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; - const accessTokens = ctx.headers.authorization; - const client = getClient(BASE_URL, accessTokens); try { - const data = await client.getStatus( - convertId(ctx.params.id, IdType.IceshrimpId), - ); - ctx.body = convertStatus(data.data); + const auth = await authenticate(ctx.headers.authorization, null); + const user = auth[0]; + + if (!auth || !user) { + ctx.status = 401; + return; + } + + const noteId = convertId(ctx.params.id, IdType.IceshrimpId); + const note = await getNote(noteId, user).then(n => n).catch(() => null); + + if (!note) { + ctx.status = 404; + return; + } + + const status = await NoteConverter.encode(note, user); + ctx.body = convertStatus(status); } catch (e: any) { console.error(e); ctx.status = ctx.status == 404 ? 404 : 401; diff --git a/packages/backend/src/server/api/mastodon/entities/account.ts b/packages/backend/src/server/api/mastodon/entities/account.ts new file mode 100644 index 000000000..15fdc6a1f --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/account.ts @@ -0,0 +1,27 @@ +/// +/// +/// +namespace MastodonEntity { + export type Account = { + id: string; + username: string; + acct: string; + display_name: string; + locked: boolean; + created_at: string; + followers_count: number; + following_count: number; + statuses_count: number; + note: string; + url: string; + avatar: string; + avatar_static: string; + header: string; + header_static: string; + emojis: Array; + moved: Account | null; + fields: Array; + bot: boolean | null; + source?: Source; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/activity.ts b/packages/backend/src/server/api/mastodon/entities/activity.ts new file mode 100644 index 000000000..1945867e0 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/activity.ts @@ -0,0 +1,8 @@ +namespace MastodonEntity { + export type Activity = { + week: string; + statuses: string; + logins: string; + registrations: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/announcement.ts b/packages/backend/src/server/api/mastodon/entities/announcement.ts new file mode 100644 index 000000000..507dbed5e --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/announcement.ts @@ -0,0 +1,34 @@ +/// +/// +/// + +namespace MastodonEntity { + export type Announcement = { + id: string; + content: string; + starts_at: string | null; + ends_at: string | null; + published: boolean; + all_day: boolean; + published_at: string; + updated_at: string; + read?: boolean; + mentions: Array; + statuses: Array; + tags: Array; + emojis: Array; + reactions: Array; + }; + + export type AnnouncementAccount = { + id: string; + username: string; + url: string; + acct: string; + }; + + export type AnnouncementStatus = { + id: string; + url: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/application.ts b/packages/backend/src/server/api/mastodon/entities/application.ts new file mode 100644 index 000000000..d58c503d9 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/application.ts @@ -0,0 +1,7 @@ +namespace MastodonEntity { + export type Application = { + name: string; + website?: string | null; + vapid_key?: string | null; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/async_attachment.ts b/packages/backend/src/server/api/mastodon/entities/async_attachment.ts new file mode 100644 index 000000000..6fefabe03 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/async_attachment.ts @@ -0,0 +1,14 @@ +/// +namespace MastodonEntity { + export type AsyncAttachment = { + id: string; + type: "unknown" | "image" | "gifv" | "video" | "audio"; + url: string | null; + remote_url: string | null; + preview_url: string; + text_url: string | null; + meta: Meta | null; + description: string | null; + blurhash: string | null; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/attachment.ts b/packages/backend/src/server/api/mastodon/entities/attachment.ts new file mode 100644 index 000000000..7dfed4fd7 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/attachment.ts @@ -0,0 +1,49 @@ +namespace MastodonEntity { + export type Sub = { + // For Image, Gifv, and Video + width?: number; + height?: number; + size?: string; + aspect?: number; + + // For Gifv and Video + frame_rate?: string; + + // For Audio, Gifv, and Video + duration?: number; + bitrate?: number; + }; + + export type Focus = { + x: number; + y: number; + }; + + export type Meta = { + original?: Sub; + small?: Sub; + focus?: Focus; + length?: string; + duration?: number; + fps?: number; + size?: string; + width?: number; + height?: number; + aspect?: number; + audio_encode?: string; + audio_bitrate?: string; + audio_channel?: string; + }; + + export type Attachment = { + id: string; + type: "unknown" | "image" | "gifv" | "video" | "audio"; + url: string; + remote_url: string | null; + preview_url: string | null; + text_url: string | null; + meta: Meta | null; + description: string | null; + blurhash: string | null; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/card.ts b/packages/backend/src/server/api/mastodon/entities/card.ts new file mode 100644 index 000000000..b1c12becd --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/card.ts @@ -0,0 +1,16 @@ +namespace MastodonEntity { + export type Card = { + url: string; + title: string; + description: string; + type: "link" | "photo" | "video" | "rich"; + image?: string; + author_name?: string; + author_url?: string; + provider_name?: string; + provider_url?: string; + html?: string; + width?: number; + height?: number; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/context.ts b/packages/backend/src/server/api/mastodon/entities/context.ts new file mode 100644 index 000000000..918e6ff66 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/context.ts @@ -0,0 +1,8 @@ +/// + +namespace MastodonEntity { + export type Context = { + ancestors: Array; + descendants: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/conversation.ts b/packages/backend/src/server/api/mastodon/entities/conversation.ts new file mode 100644 index 000000000..3822a4355 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/conversation.ts @@ -0,0 +1,11 @@ +/// +/// + +namespace MastodonEntity { + export type Conversation = { + id: string; + accounts: Array; + last_status: Status | null; + unread: boolean; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/emoji.ts b/packages/backend/src/server/api/mastodon/entities/emoji.ts new file mode 100644 index 000000000..cbb800ffa --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/emoji.ts @@ -0,0 +1,9 @@ +namespace MastodonEntity { + export type Emoji = { + shortcode: string; + static_url: string; + url: string; + visible_in_picker: boolean; + category: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/featured_tag.ts b/packages/backend/src/server/api/mastodon/entities/featured_tag.ts new file mode 100644 index 000000000..1d575aa1b --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/featured_tag.ts @@ -0,0 +1,8 @@ +namespace MastodonEntity { + export type FeaturedTag = { + id: string; + name: string; + statuses_count: number; + last_status_at: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/field.ts b/packages/backend/src/server/api/mastodon/entities/field.ts new file mode 100644 index 000000000..0dfb8bfad --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/field.ts @@ -0,0 +1,7 @@ +namespace MastodonEntity { + export type Field = { + name: string; + value: string; + verified_at: string | null; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/filter.ts b/packages/backend/src/server/api/mastodon/entities/filter.ts new file mode 100644 index 000000000..ba48a8d57 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/filter.ts @@ -0,0 +1,12 @@ +namespace MastodonEntity { + export type Filter = { + id: string; + phrase: string; + context: Array; + expires_at: string | null; + irreversible: boolean; + whole_word: boolean; + }; + + export type FilterContext = string; +} diff --git a/packages/backend/src/server/api/mastodon/entities/history.ts b/packages/backend/src/server/api/mastodon/entities/history.ts new file mode 100644 index 000000000..5ef617584 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/history.ts @@ -0,0 +1,7 @@ +namespace MastodonEntity { + export type History = { + day: string; + uses: number; + accounts: number; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/identity_proof.ts b/packages/backend/src/server/api/mastodon/entities/identity_proof.ts new file mode 100644 index 000000000..4dcdf67f7 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/identity_proof.ts @@ -0,0 +1,9 @@ +namespace MastodonEntity { + export type IdentityProof = { + provider: string; + provider_username: string; + updated_at: string; + proof_url: string; + profile_url: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/instance.ts b/packages/backend/src/server/api/mastodon/entities/instance.ts new file mode 100644 index 000000000..8b7046c09 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/instance.ts @@ -0,0 +1,41 @@ +/// +/// +/// + +namespace MastodonEntity { + export type Instance = { + uri: string; + title: string; + description: string; + email: string; + version: string; + thumbnail: string | null; + urls: URLs; + stats: Stats; + languages: Array; + contact_account: Account | null; + max_toot_chars?: number; + registrations?: boolean; + configuration?: { + statuses: { + max_characters: number; + max_media_attachments: number; + characters_reserved_per_url: number; + }; + media_attachments: { + supported_mime_types: Array; + image_size_limit: number; + image_matrix_limit: number; + video_size_limit: number; + video_frame_limit: number; + video_matrix_limit: number; + }; + polls: { + max_options: number; + max_characters_per_option: number; + min_expiration: number; + max_expiration: number; + }; + }; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/list.ts b/packages/backend/src/server/api/mastodon/entities/list.ts new file mode 100644 index 000000000..72a93c79f --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/list.ts @@ -0,0 +1,6 @@ +namespace MastodonEntity { + export type List = { + id: string; + title: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/marker.ts b/packages/backend/src/server/api/mastodon/entities/marker.ts new file mode 100644 index 000000000..ad67b84bb --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/marker.ts @@ -0,0 +1,15 @@ +namespace MastodonEntity { + export type Marker = { + home?: { + last_read_id: string; + version: number; + updated_at: string; + }; + notifications?: { + last_read_id: string; + version: number; + updated_at: string; + unread_count?: number; + }; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/mention.ts b/packages/backend/src/server/api/mastodon/entities/mention.ts new file mode 100644 index 000000000..90ada1869 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/mention.ts @@ -0,0 +1,8 @@ +namespace MastodonEntity { + export type Mention = { + id: string; + username: string; + url: string; + acct: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/notification.ts b/packages/backend/src/server/api/mastodon/entities/notification.ts new file mode 100644 index 000000000..2d3f440c1 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/notification.ts @@ -0,0 +1,15 @@ +/// +/// + +namespace MastodonEntity { + export type Notification = { + account: Account; + created_at: string; + id: string; + status?: Status; + reaction?: Reaction; + type: NotificationType; + }; + + export type NotificationType = string; +} diff --git a/packages/backend/src/server/api/mastodon/entities/poll.ts b/packages/backend/src/server/api/mastodon/entities/poll.ts new file mode 100644 index 000000000..079486046 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/poll.ts @@ -0,0 +1,14 @@ +/// + +namespace MastodonEntity { + export type Poll = { + id: string; + expires_at: string | null; + expired: boolean; + multiple: boolean; + votes_count: number; + options: Array; + voted: boolean; + own_votes: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/poll_option.ts b/packages/backend/src/server/api/mastodon/entities/poll_option.ts new file mode 100644 index 000000000..8ee847a52 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/poll_option.ts @@ -0,0 +1,6 @@ +namespace MastodonEntity { + export type PollOption = { + title: string; + votes_count: number | null; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/preferences.ts b/packages/backend/src/server/api/mastodon/entities/preferences.ts new file mode 100644 index 000000000..752d3900f --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/preferences.ts @@ -0,0 +1,9 @@ +namespace MastodonEntity { + export type Preferences = { + "posting:default:visibility": "public" | "unlisted" | "private" | "direct"; + "posting:default:sensitive": boolean; + "posting:default:language": string | null; + "reading:expand:media": "default" | "show_all" | "hide_all"; + "reading:expand:spoilers": boolean; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/push_subscription.ts b/packages/backend/src/server/api/mastodon/entities/push_subscription.ts new file mode 100644 index 000000000..a12b35f63 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/push_subscription.ts @@ -0,0 +1,16 @@ +namespace MastodonEntity { + export type Alerts = { + follow: boolean; + favourite: boolean; + mention: boolean; + reblog: boolean; + poll: boolean; + }; + + export type PushSubscription = { + id: string; + endpoint: string; + server_key: string; + alerts: Alerts; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/reaction.ts b/packages/backend/src/server/api/mastodon/entities/reaction.ts new file mode 100644 index 000000000..34741d41f --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/reaction.ts @@ -0,0 +1,12 @@ +/// + +namespace MastodonEntity { + export type Reaction = { + count: number; + me: boolean; + name: string; + url?: string; + static_url?: string; + accounts?: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/relationship.ts b/packages/backend/src/server/api/mastodon/entities/relationship.ts new file mode 100644 index 000000000..8cb18c460 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/relationship.ts @@ -0,0 +1,17 @@ +namespace MastodonEntity { + export type Relationship = { + id: string; + following: boolean; + followed_by: boolean; + delivery_following?: boolean; + blocking: boolean; + blocked_by: boolean; + muting: boolean; + muting_notifications: boolean; + requested: boolean; + domain_blocking: boolean; + showing_reblogs: boolean; + endorsed: boolean; + notifying: boolean; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/report.ts b/packages/backend/src/server/api/mastodon/entities/report.ts new file mode 100644 index 000000000..1f87a1349 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/report.ts @@ -0,0 +1,9 @@ +namespace MastodonEntity { + export type Report = { + id: string; + action_taken: string; + comment: string; + account_id: string; + status_ids: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/results.ts b/packages/backend/src/server/api/mastodon/entities/results.ts new file mode 100644 index 000000000..882d1e7be --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/results.ts @@ -0,0 +1,11 @@ +/// +/// +/// + +namespace MastodonEntity { + export type Results = { + accounts: Array; + statuses: Array; + hashtags: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/scheduled_status.ts b/packages/backend/src/server/api/mastodon/entities/scheduled_status.ts new file mode 100644 index 000000000..1613adbfc --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/scheduled_status.ts @@ -0,0 +1,10 @@ +/// +/// +namespace MastodonEntity { + export type ScheduledStatus = { + id: string; + scheduled_at: string; + params: StatusParams; + media_attachments: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/source.ts b/packages/backend/src/server/api/mastodon/entities/source.ts new file mode 100644 index 000000000..a0ac1b869 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/source.ts @@ -0,0 +1,10 @@ +/// +namespace MastodonEntity { + export type Source = { + privacy: string | null; + sensitive: boolean | null; + language: string | null; + note: string; + fields: Array; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/stats.ts b/packages/backend/src/server/api/mastodon/entities/stats.ts new file mode 100644 index 000000000..fdb517d22 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/stats.ts @@ -0,0 +1,7 @@ +namespace MastodonEntity { + export type Stats = { + user_count: number; + status_count: number; + domain_count: number; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/status.ts b/packages/backend/src/server/api/mastodon/entities/status.ts new file mode 100644 index 000000000..76132eaf8 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/status.ts @@ -0,0 +1,45 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// + +namespace MastodonEntity { + export type Status = { + id: string; + uri: string; + url: string; + account: Account; + in_reply_to_id: string | null; + in_reply_to_account_id: string | null; + reblog: Status | null; + content: string; + text: string | null; + created_at: string; + emojis: Emoji[]; + replies_count: number; + reblogs_count: number; + favourites_count: number; + reblogged: boolean | null; + favourited: boolean | null; + muted: boolean | null; + sensitive: boolean; + spoiler_text: string; + visibility: "public" | "unlisted" | "private" | "direct"; + media_attachments: Array; + mentions: Array; + tags: Array; + card: Card | null; + poll: Poll | null; + application: Application | null; + language: string | null; + pinned: boolean | null; + reactions: Array; + quote: Status | null; + bookmarked: boolean; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/status_edit.ts b/packages/backend/src/server/api/mastodon/entities/status_edit.ts new file mode 100644 index 000000000..98405ad5c --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/status_edit.ts @@ -0,0 +1,23 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// + +namespace MastodonEntity { + export type StatusEdit = { + account: Account; + content: string; + plain_content: string | null; + created_at: string; + emojis: Emoji[]; + sensitive: boolean; + spoiler_text: string; + media_attachments: Array; + poll: Poll | null; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/status_params.ts b/packages/backend/src/server/api/mastodon/entities/status_params.ts new file mode 100644 index 000000000..58338b69e --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/status_params.ts @@ -0,0 +1,12 @@ +namespace MastodonEntity { + export type StatusParams = { + text: string; + in_reply_to_id: string | null; + media_ids: Array | null; + sensitive: boolean | null; + spoiler_text: string | null; + visibility: "public" | "unlisted" | "private" | "direct"; + scheduled_at: string | null; + application_id: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/tag.ts b/packages/backend/src/server/api/mastodon/entities/tag.ts new file mode 100644 index 000000000..1a29e67cc --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/tag.ts @@ -0,0 +1,10 @@ +/// + +namespace MastodonEntity { + export type Tag = { + name: string; + url: string; + history: Array | null; + following?: boolean; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/token.ts b/packages/backend/src/server/api/mastodon/entities/token.ts new file mode 100644 index 000000000..87011b812 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/token.ts @@ -0,0 +1,8 @@ +namespace MastodonEntity { + export type Token = { + access_token: string; + token_type: string; + scope: string; + created_at: number; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entities/urls.ts b/packages/backend/src/server/api/mastodon/entities/urls.ts new file mode 100644 index 000000000..cedc94b45 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entities/urls.ts @@ -0,0 +1,5 @@ +namespace MastodonEntity { + export type URLs = { + streaming_api: string; + }; +} diff --git a/packages/backend/src/server/api/mastodon/entity.ts b/packages/backend/src/server/api/mastodon/entity.ts new file mode 100644 index 000000000..350f0b312 --- /dev/null +++ b/packages/backend/src/server/api/mastodon/entity.ts @@ -0,0 +1,38 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// + +export default MastodonEntity;