Update Mastodon API types

This commit is contained in:
Jesse Wierzbinski 2024-04-14 00:53:21 -10:00
parent 58cd284a84
commit 82c6dc17a8
No known key found for this signature in database
107 changed files with 577 additions and 89 deletions

View file

@ -1,7 +1,7 @@
import type { InferSelectModel } from "drizzle-orm"; import type { InferSelectModel } from "drizzle-orm";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import type { application } from "~drizzle/schema"; import type { application } from "~drizzle/schema";
import type { APIApplication } from "~types/entities/application"; import type { Application as APIApplication } from "~types/mastodon/application";
export type Application = InferSelectModel<typeof application>; export type Application = InferSelectModel<typeof application>;

View file

@ -4,8 +4,8 @@ import type * as Lysand from "lysand-types";
import { MediaBackendType } from "media-manager"; import { MediaBackendType } from "media-manager";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { attachment } from "~drizzle/schema"; import { attachment } from "~drizzle/schema";
import type { APIAsyncAttachment } from "~types/entities/async_attachment"; import type { AsyncAttachment as APIAsyncAttachment } from "~types/mastodon/async_attachment";
import type { APIAttachment } from "~types/entities/attachment"; import type { Attachment as APIAttachment } from "~types/mastodon/attachment";
export type Attachment = InferSelectModel<typeof attachment>; export type Attachment = InferSelectModel<typeof attachment>;

View file

@ -2,7 +2,7 @@ import { type InferSelectModel, and, eq } from "drizzle-orm";
import type * as Lysand from "lysand-types"; import type * as Lysand from "lysand-types";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { emoji, instance } from "~drizzle/schema"; import { emoji, instance } from "~drizzle/schema";
import type { APIEmoji } from "~types/entities/emoji"; import type { Emoji as APIEmoji } from "~types/mastodon/emoji";
import { addInstanceIfNotExists } from "./Instance"; import { addInstanceIfNotExists } from "./Instance";
export type EmojiWithInstance = InferSelectModel<typeof emoji> & { export type EmojiWithInstance = InferSelectModel<typeof emoji> & {

View file

@ -1,7 +1,7 @@
import type { InferSelectModel } from "drizzle-orm"; import type { InferSelectModel } from "drizzle-orm";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import type { notification } from "~drizzle/schema"; import type { notification } from "~drizzle/schema";
import type { APINotification } from "~types/entities/notification"; import type { Notification as APINotification } from "~types/mastodon/notification";
import { import {
type StatusWithRelations, type StatusWithRelations,
findFirstStatuses, findFirstStatuses,

View file

@ -1,7 +1,7 @@
import type { InferSelectModel } from "drizzle-orm"; import type { InferSelectModel } from "drizzle-orm";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { relationship } from "~drizzle/schema"; import { relationship } from "~drizzle/schema";
import type { APIRelationship } from "~types/entities/relationship"; import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import type { User } from "./User"; import type { User } from "./User";
export type Relationship = InferSelectModel<typeof relationship>; export type Relationship = InferSelectModel<typeof relationship>;
@ -82,7 +82,6 @@ export const relationshipToAPI = (rel: Relationship): APIRelationship => {
notifying: rel.notifying, notifying: rel.notifying,
requested: rel.requested, requested: rel.requested,
showing_reblogs: rel.showingReblogs, showing_reblogs: rel.showingReblogs,
languages: rel.languages ?? [],
note: rel.note, note: rel.note,
}; };
}; };

View file

@ -5,18 +5,15 @@ import {
and, and,
eq, eq,
inArray, inArray,
isNotNull,
isNull, isNull,
or, or,
sql, sql,
} from "drizzle-orm"; } from "drizzle-orm";
import { htmlToText } from "html-to-text"; import { htmlToText } from "html-to-text";
import linkifyHtml from "linkify-html"; import linkifyHtml from "linkify-html";
import linkifyStr from "linkify-string";
import type * as Lysand from "lysand-types"; import type * as Lysand from "lysand-types";
import { import {
anyOf, anyOf,
char,
charIn, charIn,
createRegExp, createRegExp,
digit, digit,
@ -38,9 +35,9 @@ import {
statusToMentions, statusToMentions,
user, user,
} from "~drizzle/schema"; } from "~drizzle/schema";
import type { APIAttachment } from "~types/entities/attachment";
import type { APIStatus } from "~types/entities/status";
import type { Note } from "~types/lysand/Object"; import type { Note } from "~types/lysand/Object";
import type { Attachment as APIAttachment } from "~types/mastodon/attachment";
import type { Status as APIStatus } from "~types/mastodon/status";
import { applicationToAPI } from "./Application"; import { applicationToAPI } from "./Application";
import { import {
attachmentFromLysand, attachmentFromLysand,
@ -64,7 +61,6 @@ import {
resolveUser, resolveUser,
resolveWebFinger, resolveWebFinger,
transformOutputToUserWithRelations, transformOutputToUserWithRelations,
userExtras,
userExtrasTemplate, userExtrasTemplate,
userRelations, userRelations,
userToAPI, userToAPI,
@ -1270,12 +1266,13 @@ export const statusToAPI = async (
config.http.base_url, config.http.base_url,
).toString(), ).toString(),
bookmarked: false, bookmarked: false,
quote: statusToConvert.quoting quote: !!statusToConvert.quotingPostId /* statusToConvert.quoting
? await statusToAPI( ? await statusToAPI(
statusToConvert.quoting as unknown as StatusWithRelations, statusToConvert.quoting as unknown as StatusWithRelations,
userFetching, userFetching,
) )
: null, : null, */,
// @ts-expect-error Pleroma extension
quote_id: statusToConvert.quotingPostId || undefined, quote_id: statusToConvert.quotingPostId || undefined,
}; };
}; };

View file

@ -12,8 +12,8 @@ import {
relationship, relationship,
user, user,
} from "~drizzle/schema"; } from "~drizzle/schema";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import type { APISource } from "~types/entities/source"; import type { Source as APISource } from "~types/mastodon/source";
import { import {
type EmojiWithInstance, type EmojiWithInstance,
emojiToAPI, emojiToAPI,
@ -749,6 +749,7 @@ export const userToAPI = (
discoverable: undefined, discoverable: undefined,
mute_expires_at: undefined, mute_expires_at: undefined,
group: false, group: false,
// @ts-expect-error Pleroma extension
pleroma: { pleroma: {
is_admin: userToConvert.isAdmin, is_admin: userToConvert.isAdmin,
is_moderator: userToConvert.isAdmin, is_moderator: userToConvert.isAdmin,

View file

@ -6,7 +6,7 @@ import {
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./index"; import { meta } from "./index";
await deleteOldTestUsers(); await deleteOldTestUsers();
@ -86,6 +86,7 @@ describe(meta.route, () => {
limited: false, limited: false,
noindex: false, noindex: false,
suspended: false, suspended: false,
// @ts-expect-error Pleroma extension
pleroma: { pleroma: {
is_admin: false, is_admin: false,
is_moderator: false, is_moderator: false,

View file

@ -1,6 +1,7 @@
import { apiRoute, applyConfig, idValidator } from "@api"; import { apiRoute, applyConfig, idValidator } from "@api";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { z } from "zod";
import { relationshipToAPI } from "~database/entities/Relationship"; import { relationshipToAPI } from "~database/entities/Relationship";
import { import {
findFirstUser, findFirstUser,
@ -8,7 +9,6 @@ import {
} from "~database/entities/User"; } from "~database/entities/User";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { relationship } from "~drizzle/schema"; import { relationship } from "~drizzle/schema";
import { z } from "zod";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -1,14 +1,11 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { afterAll, describe, expect, test } from "bun:test";
import { getUserUri } from "~database/entities/User";
import { config } from "~index"; import { config } from "~index";
import { import {
deleteOldTestUsers, deleteOldTestUsers,
getTestStatuses,
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import type { APIStatus } from "~types/entities/status";
import { meta } from "./index"; import { meta } from "./index";
await deleteOldTestUsers(); await deleteOldTestUsers();

View file

@ -6,10 +6,10 @@ import {
createRegExp, createRegExp,
digit, digit,
exactly, exactly,
global,
letter, letter,
maybe, maybe,
oneOrMore, oneOrMore,
global,
} from "magic-regexp"; } from "magic-regexp";
import { z } from "zod"; import { z } from "zod";
import { import {

View file

@ -1,13 +1,11 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { afterAll, describe, expect, test } from "bun:test";
import { getUserUri } from "~database/entities/User";
import { config } from "~index"; import { config } from "~index";
import { import {
deleteOldTestUsers, deleteOldTestUsers,
getTestStatuses,
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./index"; import { meta } from "./index";
await deleteOldTestUsers(); await deleteOldTestUsers();

View file

@ -2,15 +2,15 @@ import { apiRoute, applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { sql } from "drizzle-orm"; import { sql } from "drizzle-orm";
import { import {
createRegExp,
maybe,
oneOrMore,
anyOf, anyOf,
letter,
digit,
charIn, charIn,
createRegExp,
digit,
exactly, exactly,
global, global,
letter,
maybe,
oneOrMore,
} from "magic-regexp"; } from "magic-regexp";
import { z } from "zod"; import { z } from "zod";
import { import {

View file

@ -2,6 +2,7 @@ import { apiRoute, applyConfig } from "@api";
import { convertTextToHtml } from "@formatting"; import { convertTextToHtml } from "@formatting";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { sanitizeHtml } from "@sanitization"; import { sanitizeHtml } from "@sanitization";
import { config } from "config-manager";
import { and, eq } from "drizzle-orm"; import { and, eq } from "drizzle-orm";
import ISO6391 from "iso-639-1"; import ISO6391 from "iso-639-1";
import { MediaBackendType } from "media-manager"; import { MediaBackendType } from "media-manager";
@ -13,8 +14,7 @@ import { parseEmojis } from "~database/entities/Emoji";
import { findFirstUser, userToAPI } from "~database/entities/User"; import { findFirstUser, userToAPI } from "~database/entities/User";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { emojiToUser, user } from "~drizzle/schema"; import { emojiToUser, user } from "~drizzle/schema";
import { config } from "config-manager"; import type { Source as APISource } from "~types/mastodon/source";
import type { APISource } from "~types/entities/source";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["PATCH"], allowedMethods: ["PATCH"],

View file

@ -1,9 +1,9 @@
import { randomBytes } from "node:crypto"; import { randomBytes } from "node:crypto";
import { apiRoute, applyConfig } from "@api"; import { apiRoute, applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { z } from "zod";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { application } from "~drizzle/schema"; import { application } from "~drizzle/schema";
import { z } from "zod";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -5,7 +5,7 @@ import { findFirstUser, userToAPI } from "~database/entities/User";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { instance, status, user } from "~drizzle/schema"; import { instance, status, user } from "~drizzle/schema";
import manifest from "~package.json"; import manifest from "~package.json";
import type { APIInstance } from "~types/entities/instance"; import type { Instance as APIInstance } from "~types/mastodon/instance";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["GET"], allowedMethods: ["GET"],
@ -81,14 +81,6 @@ export default apiRoute(async (req, matchedRoute, extraData) => {
return jsonResponse({ return jsonResponse({
approval_required: false, approval_required: false,
configuration: { configuration: {
media_attachments: {
image_matrix_limit: config.validation.max_media_attachments,
image_size_limit: config.validation.max_media_size,
supported_mime_types: config.validation.allowed_mime_types,
video_frame_limit: 60,
video_matrix_limit: 10,
video_size_limit: config.validation.max_media_size,
},
polls: { polls: {
max_characters_per_option: max_characters_per_option:
config.validation.max_poll_option_size, config.validation.max_poll_option_size,
@ -100,11 +92,6 @@ export default apiRoute(async (req, matchedRoute, extraData) => {
characters_reserved_per_url: 0, characters_reserved_per_url: 0,
max_characters: config.validation.max_note_size, max_characters: config.validation.max_note_size,
max_media_attachments: config.validation.max_media_attachments, max_media_attachments: config.validation.max_media_attachments,
supported_mime_types: [
"text/plain",
"text/markdown",
"text/html",
],
}, },
}, },
description: "A test instance", description: "A test instance",
@ -122,14 +109,12 @@ export default apiRoute(async (req, matchedRoute, extraData) => {
user_count: userCount, user_count: userCount,
}, },
thumbnail: config.instance.logo, thumbnail: config.instance.logo,
tos_url: config.signups.tos_url,
title: config.instance.name, title: config.instance.name,
uri: config.http.base_url, uri: config.http.base_url,
urls: { urls: {
streaming_api: "", streaming_api: "",
}, },
version: `4.3.0+glitch (compatible; Lysand ${version}})`, version: `4.3.0+glitch (compatible; Lysand ${version}})`,
max_toot_chars: config.validation.max_note_size,
pleroma: { pleroma: {
metadata: { metadata: {
account_activation_required: false, account_activation_required: false,
@ -199,7 +184,6 @@ export default apiRoute(async (req, matchedRoute, extraData) => {
}, },
vapid_public_key: "", vapid_public_key: "",
}, },
// @ts-expect-error Sometimes there just isnt an admin
contact_account: contactAccount ? userToAPI(contactAccount) : undefined, contact_account: contactAccount ? userToAPI(contactAccount) : undefined,
} satisfies APIInstance & { } satisfies APIInstance & {
pleroma: object; pleroma: object;

View file

@ -1,5 +1,6 @@
import { apiRoute, applyConfig, idValidator } from "@api"; import { apiRoute, applyConfig, idValidator } from "@api";
import { errorResponse, jsonResponse, response } from "@response"; import { errorResponse, jsonResponse, response } from "@response";
import { config } from "config-manager";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import type { MediaBackend } from "media-manager"; import type { MediaBackend } from "media-manager";
import { MediaBackendType } from "media-manager"; import { MediaBackendType } from "media-manager";
@ -8,7 +9,6 @@ import { z } from "zod";
import { attachmentToAPI, getUrl } from "~database/entities/Attachment"; import { attachmentToAPI, getUrl } from "~database/entities/Attachment";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { attachment } from "~drizzle/schema"; import { attachment } from "~drizzle/schema";
import { config } from "config-manager";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["GET", "PUT"], allowedMethods: ["GET", "PUT"],

View file

@ -1,6 +1,7 @@
import { apiRoute, applyConfig } from "@api"; import { apiRoute, applyConfig } from "@api";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { encode } from "blurhash"; import { encode } from "blurhash";
import { config } from "config-manager";
import { MediaBackendType } from "media-manager"; import { MediaBackendType } from "media-manager";
import type { MediaBackend } from "media-manager"; import type { MediaBackend } from "media-manager";
import { LocalMediaBackend, S3MediaBackend } from "media-manager"; import { LocalMediaBackend, S3MediaBackend } from "media-manager";
@ -9,7 +10,6 @@ import { z } from "zod";
import { attachmentToAPI, getUrl } from "~database/entities/Attachment"; import { attachmentToAPI, getUrl } from "~database/entities/Attachment";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { attachment } from "~drizzle/schema"; import { attachment } from "~drizzle/schema";
import { config } from "config-manager";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -7,7 +7,7 @@ import {
statusToAPI, statusToAPI,
} from "~database/entities/Status"; } from "~database/entities/Status";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -6,7 +6,7 @@ import {
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./favourited_by"; import { meta } from "./favourited_by";
await deleteOldTestUsers(); await deleteOldTestUsers();

View file

@ -1,7 +1,9 @@
import { apiRoute, applyConfig, idValidator } from "@api"; import { apiRoute, applyConfig, idValidator } from "@api";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { sanitizeHtml } from "@sanitization"; import { sanitizeHtml } from "@sanitization";
import { config } from "config-manager";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import ISO6391 from "iso-639-1";
import { parse } from "marked"; import { parse } from "marked";
import { z } from "zod"; import { z } from "zod";
import { import {
@ -12,8 +14,6 @@ import {
} from "~database/entities/Status"; } from "~database/entities/Status";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { status } from "~drizzle/schema"; import { status } from "~drizzle/schema";
import { config } from "config-manager";
import ISO6391 from "iso-639-1";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["GET", "DELETE", "PUT"], allowedMethods: ["GET", "DELETE", "PUT"],

View file

@ -6,8 +6,7 @@ import {
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import type { APIStatus } from "~types/entities/status";
import { meta } from "./reblogged_by"; import { meta } from "./reblogged_by";
await deleteOldTestUsers(); await deleteOldTestUsers();

View file

@ -6,7 +6,7 @@ import {
isViewableByUser, isViewableByUser,
statusToAPI, statusToAPI,
} from "~database/entities/Status"; } from "~database/entities/Status";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -8,7 +8,7 @@ import {
} from "~database/entities/Status"; } from "~database/entities/Status";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { status } from "~drizzle/schema"; import { status } from "~drizzle/schema";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -5,7 +5,7 @@ import {
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./index"; import { meta } from "./index";
await deleteOldTestUsers(); await deleteOldTestUsers();
@ -292,6 +292,7 @@ describe(meta.route, () => {
const object2 = (await response2.json()) as APIStatus; const object2 = (await response2.json()) as APIStatus;
expect(object2.content).toBe("<p>Hello, world again!</p>"); expect(object2.content).toBe("<p>Hello, world again!</p>");
// @ts-expect-error Pleroma extension
expect(object2.quote_id).toBe(object.id); expect(object2.quote_id).toBe(object.id);
}); });

View file

@ -1,6 +1,8 @@
import { apiRoute, applyConfig, idValidator } from "@api"; import { apiRoute, applyConfig, idValidator } from "@api";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { sanitizeHtml } from "@sanitization"; import { sanitizeHtml } from "@sanitization";
import { config } from "config-manager";
import ISO6391 from "iso-639-1";
import { parse } from "marked"; import { parse } from "marked";
import { z } from "zod"; import { z } from "zod";
import type { StatusWithRelations } from "~database/entities/Status"; import type { StatusWithRelations } from "~database/entities/Status";
@ -12,8 +14,6 @@ import {
statusToAPI, statusToAPI,
} from "~database/entities/Status"; } from "~database/entities/Status";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { config } from "config-manager";
import ISO6391 from "iso-639-1";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["POST"], allowedMethods: ["POST"],

View file

@ -6,7 +6,7 @@ import {
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./home"; import { meta } from "./home";
await deleteOldTestUsers(); await deleteOldTestUsers();

View file

@ -6,7 +6,7 @@ import {
getTestUsers, getTestUsers,
sendTestRequest, sendTestRequest,
} from "~tests/utils"; } from "~tests/utils";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./public"; import { meta } from "./public";
await deleteOldTestUsers(); await deleteOldTestUsers();

View file

@ -3,8 +3,8 @@ import { config } from "config-manager";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { db } from "~drizzle/db"; import { db } from "~drizzle/db";
import { emoji } from "~drizzle/schema"; import { emoji } from "~drizzle/schema";
import type { APIEmoji } from "~types/entities/emoji"; import type { Emoji as APIEmoji } from "~types/mastodon/emoji";
import type { APIInstance } from "~types/entities/instance"; import type { Instance as APIInstance } from "~types/mastodon/instance";
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils"; import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
const base_url = config.http.base_url; const base_url = config.http.base_url;
@ -44,7 +44,6 @@ describe("API Tests", () => {
// expect(instance.contact_account).toBeDefined(); // expect(instance.contact_account).toBeDefined();
expect(instance.rules).toBeDefined(); expect(instance.rules).toBeDefined();
expect(instance.approval_required).toBeDefined(); expect(instance.approval_required).toBeDefined();
expect(instance.max_toot_chars).toBeDefined();
}); });
}); });

View file

@ -1,9 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager"; import { config } from "config-manager";
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~tests/utils"; import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~tests/utils";
import type { APIAccount } from "~types/entities/account"; import type { Account as APIAccount } from "~types/mastodon/account";
import type { APIRelationship } from "~types/entities/relationship"; import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import type { APIStatus } from "~types/entities/status"; import type { Status as APIStatus } from "~types/mastodon/status";
const base_url = config.http.base_url; const base_url = config.http.base_url;

View file

@ -1,16 +1,10 @@
import { afterAll, describe, expect, test } from "bun:test"; import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager"; import { config } from "config-manager";
import { statusToAPI } from "~database/entities/Status"; import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~tests/utils";
import { import type { Account as APIAccount } from "~types/mastodon/account";
getTestStatuses, import type { AsyncAttachment as APIAsyncAttachment } from "~types/mastodon/async_attachment";
getTestUsers, import type { Context as APIContext } from "~types/mastodon/context";
sendTestRequest, import type { Status as APIStatus } from "~types/mastodon/status";
wrapRelativeUrl,
} from "~tests/utils";
import type { APIAccount } from "~types/entities/account";
import type { APIAsyncAttachment } from "~types/entities/async_attachment";
import type { APIContext } from "~types/entities/context";
import type { APIStatus } from "~types/entities/status";
const base_url = config.http.base_url; const base_url = config.http.base_url;

View file

@ -1,6 +1,6 @@
import { afterAll, describe, expect, test } from "bun:test"; import { afterAll, describe, expect, test } from "bun:test";
import type { APIApplication } from "~types/entities/application"; import type { Application as APIApplication } from "~types/mastodon/application";
import type { APIToken } from "~types/entities/token"; import type { Token as APIToken } from "~types/mastodon/token";
import { import {
deleteOldTestUsers, deleteOldTestUsers,
getTestUsers, getTestUsers,

34
types/mastodon/account.ts Normal file
View file

@ -0,0 +1,34 @@
import type { Emoji } from "./emoji";
import type { Field } from "./field";
import type { Role } from "./role";
import type { Source } from "./source";
export type Account = {
id: string;
username: string;
acct: string;
display_name: string;
locked: boolean;
discoverable?: boolean;
group: boolean | null;
noindex: boolean | null;
suspended: boolean | null;
limited: boolean | null;
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<Emoji>;
moved: Account | null;
fields: Array<Field>;
bot: boolean | null;
source?: Source;
role?: Role;
mute_expires_at?: string;
};

View file

@ -0,0 +1,6 @@
export type Activity = {
week: string;
statuses: string;
logins: string;
registrations: string;
};

View file

@ -0,0 +1,39 @@
import type { Emoji } from "./emoji";
import type { StatusTag } from "./status";
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 | null;
read: boolean | null;
mentions: Array<AnnouncementAccount>;
statuses: Array<AnnouncementStatus>;
tags: Array<StatusTag>;
emojis: Array<Emoji>;
reactions: Array<AnnouncementReaction>;
};
export type AnnouncementAccount = {
id: string;
username: string;
url: string;
acct: string;
};
export type AnnouncementStatus = {
id: string;
url: string;
};
export type AnnouncementReaction = {
name: string;
count: number;
me: boolean | null;
url: string | null;
static_url: string | null;
};

View file

@ -0,0 +1,5 @@
export type Application = {
name: string;
website?: string | null;
vapid_key?: string | null;
};

View file

@ -0,0 +1,13 @@
import type { Meta } from "./attachment";
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;
};

View file

@ -0,0 +1,47 @@
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;
};

16
types/mastodon/card.ts Normal file
View file

@ -0,0 +1,16 @@
export type Card = {
url: string;
title: string;
description: string;
type: "link" | "photo" | "video" | "rich";
image: string | null;
author_name: string | null;
author_url: string | null;
provider_name: string | null;
provider_url: string | null;
html: string | null;
width: number | null;
height: number | null;
embed_url: string | null;
blurhash: string | null;
};

View file

@ -0,0 +1,6 @@
import type { Status } from "./status";
export type Context = {
ancestors: Array<Status>;
descendants: Array<Status>;
};

View file

@ -0,0 +1,9 @@
import type { Account } from "./account";
import type { Status } from "./status";
export type Conversation = {
id: string;
accounts: Array<Account>;
last_status: Status | null;
unread: boolean;
};

7
types/mastodon/emoji.ts Normal file
View file

@ -0,0 +1,7 @@
export type Emoji = {
shortcode: string;
static_url: string;
url: string;
visible_in_picker: boolean;
category?: string;
};

View file

@ -0,0 +1,6 @@
export type FeaturedTag = {
id: string;
name: string;
statuses_count: number;
last_status_at: string;
};

6
types/mastodon/field.ts Normal file
View file

@ -0,0 +1,6 @@
export type Field = {
name: string;
value: string;
verified_at?: string | null;
verified?: boolean | false;
};

10
types/mastodon/filter.ts Normal file
View file

@ -0,0 +1,10 @@
export type Filter = {
id: string;
phrase: string;
context: Array<FilterContext>;
expires_at: string | null;
irreversible: boolean;
whole_word: boolean;
};
export type FilterContext = string;

View file

@ -0,0 +1,25 @@
import type { Emoji } from "./emoji";
import type { Field } from "./field";
export type FollowRequest = {
id: number;
username: string;
acct: string;
display_name: string;
locked: boolean;
bot: boolean;
discoverable?: boolean;
group: boolean;
created_at: string;
note: string;
url: string;
avatar: string;
avatar_static: string;
header: string;
header_static: string;
followers_count: number;
following_count: number;
statuses_count: number;
emojis: Array<Emoji>;
fields: Array<Field>;
};

View file

@ -0,0 +1,5 @@
export type History = {
day: string;
uses: number;
accounts: number;
};

View file

@ -0,0 +1,7 @@
export type IdentityProof = {
provider: string;
provider_username: string;
updated_at: string;
proof_url: string;
profile_url: string;
};

View file

@ -0,0 +1,38 @@
import type { Account } from "./account";
import type { Stats } from "./stats";
import type { URLs } from "./urls";
export type Instance = {
uri: string;
title: string;
description: string;
email: string;
version: string;
thumbnail: string | null;
urls: URLs | null;
stats: Stats;
languages: Array<string>;
registrations: boolean;
approval_required: boolean;
invites_enabled?: boolean;
configuration: {
statuses: {
max_characters: number;
max_media_attachments?: number;
characters_reserved_per_url?: number;
};
polls?: {
max_options: number;
max_characters_per_option: number;
min_expiration: number;
max_expiration: number;
};
};
contact_account?: Account;
rules?: Array<InstanceRule>;
};
export type InstanceRule = {
id: string;
text: string;
};

7
types/mastodon/list.ts Normal file
View file

@ -0,0 +1,7 @@
export type List = {
id: string;
title: string;
replies_policy: RepliesPolicy | null;
};
export type RepliesPolicy = "followed" | "list" | "none";

13
types/mastodon/marker.ts Normal file
View file

@ -0,0 +1,13 @@
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;
};
};

View file

@ -0,0 +1,6 @@
export type Mention = {
id: string;
username: string;
url: string;
acct: string;
};

View file

@ -0,0 +1,15 @@
import type { Account } from "./account";
import type { Reaction } from "./reaction";
import type { Status } from "./status";
export type Notification = {
account: Account | null;
created_at: string;
id: string;
status?: Status;
reaction?: Reaction;
type: NotificationType;
target?: Account;
};
export type NotificationType = string;

14
types/mastodon/poll.ts Normal file
View file

@ -0,0 +1,14 @@
export type Poll = {
id: string;
expires_at: string | null;
expired: boolean;
multiple: boolean;
votes_count: number;
options: Array<PollOption>;
voted: boolean;
};
export type PollOption = {
title: string;
votes_count: number | null;
};

View file

@ -0,0 +1,9 @@
import type { StatusVisibility } from "./status";
export type Preferences = {
"posting:default:visibility": StatusVisibility;
"posting:default:sensitive": boolean;
"posting:default:language": string | null;
"reading:expand:media": "default" | "show_all" | "hide_all";
"reading:expand:spoilers": boolean;
};

View file

@ -0,0 +1,14 @@
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;
};

View file

@ -0,0 +1,11 @@
import type { Account } from "./account";
export type Reaction = {
count: number;
me: boolean;
name: string;
url?: string;
static_url?: string;
accounts?: Array<Account>;
account_ids?: Array<string>;
};

View file

@ -0,0 +1,15 @@
export type Relationship = {
id: string;
following: boolean;
followed_by: boolean;
blocking: boolean;
blocked_by: boolean;
muting: boolean;
muting_notifications: boolean;
requested: boolean;
domain_blocking: boolean;
showing_reblogs: boolean;
endorsed: boolean;
notifying: boolean;
note: string | null;
};

16
types/mastodon/report.ts Normal file
View file

@ -0,0 +1,16 @@
import type { Account } from "./account";
export type Report = {
id: string;
action_taken: boolean;
action_taken_at: string | null;
status_ids: Array<string> | null;
rule_ids: Array<string> | null;
// These parameters don't exist in Pleroma
category: Category | null;
comment: string | null;
forwarded: boolean | null;
target_account?: Account | null;
};
export type Category = "spam" | "violation" | "other";

View file

@ -0,0 +1,9 @@
import type { Account } from "./account";
import type { Status } from "./status";
import type { Tag } from "./tag";
export type Results = {
accounts: Array<Account>;
statuses: Array<Status>;
hashtags: Array<Tag>;
};

3
types/mastodon/role.ts Normal file
View file

@ -0,0 +1,3 @@
export type Role = {
name: string;
};

View file

@ -0,0 +1,9 @@
import type { Attachment } from "./attachment";
import type { StatusParams } from "./status_params";
export type ScheduledStatus = {
id: string;
scheduled_at: string;
params: StatusParams;
media_attachments: Array<Attachment> | null;
};

9
types/mastodon/source.ts Normal file
View file

@ -0,0 +1,9 @@
import type { Field } from "./field";
export type Source = {
privacy: string | null;
sensitive: boolean | null;
language: string | null;
note: string;
fields: Array<Field>;
};

Some files were not shown because too many files have changed in this diff Show more