From 122842c00ecb94882ec7cda44512c53b4a198725 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 28 Nov 2024 10:41:20 +0100 Subject: [PATCH] feat(client): :sparkles: Add Emoji API --- client/types/emoji.ts | 1 + client/types/versia.ts | 2 +- client/versia/client.ts | 87 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/client/types/emoji.ts b/client/types/emoji.ts index cc8de67..53c719d 100644 --- a/client/types/emoji.ts +++ b/client/types/emoji.ts @@ -1,4 +1,5 @@ export type Emoji = { + id: string; shortcode: string; static_url: string; url: string; diff --git a/client/types/versia.ts b/client/types/versia.ts index 39cca0e..59e42e9 100644 --- a/client/types/versia.ts +++ b/client/types/versia.ts @@ -8,7 +8,7 @@ export type VersiaRole = { icon: string | null; }; -// Last updated: 2024-06-07 +// Last updated: 2024-11-28 export enum RolePermission { ManageNotes = "notes", ManageOwnNotes = "owner:note", diff --git a/client/versia/client.ts b/client/versia/client.ts index f08eca6..7c1c435 100644 --- a/client/versia/client.ts +++ b/client/versia/client.ts @@ -276,6 +276,16 @@ export class Client extends BaseClient { ); } + /** + * DELETE /api/v1/emojis/:id + * + * @param id The emoji to delete's ID. + * @return Empty. + */ + public deleteEmoji(id: string, extra?: RequestInit): Promise> { + return this.delete(`/api/v1/emojis/${id}`, undefined, extra); + } + /** * DELETE /api/v1/statuses/:id/reactions/:emoji * @@ -903,6 +913,16 @@ export class Client extends BaseClient { return this.get(`/api/v1/domain_blocks?${params}`); } + /** + * GET /api/v1/emojis/:id + * + * @param id The emoji ID. + * @return Emoji. + */ + public getEmoji(id: string, extra?: RequestInit): Promise> { + return this.get(`/api/v1/emojis/${id}`, extra); + } + /** * GET /api/v1/endorsements * @@ -2640,6 +2660,42 @@ export class Client extends BaseClient { ); } + /** + * PATCH /api/v1/emojis/:id + * + * @param id Target emoji ID. + * @param options.shortcode Emoji shortcode. + * @param options.image Emoji image, as a File, or a URL. + * @param options.category Emoji category. + * @param options.alt Emoji description. + * @param options.global Whether the emoji should be visible to all users (requires `emoji` permission). + * @return Emoji. + */ + public updateEmoji( + id: string, + options: Partial<{ + alt: string; + category: string; + global: boolean; + image: File | URL; + shortcode: string; + }>, + extra?: RequestInit, + ): Promise> { + return this.patchForm( + `/api/v1/emojis/${id}`, + { + ...options, + image: undefined, + element: + options.image instanceof File + ? options.image + : options.image?.toString(), + }, + extra, + ); + } + // TODO: updateFilter /** @@ -2731,6 +2787,37 @@ export class Client extends BaseClient { ); } + /** + * POST /api/v1/emojis + * + * @param shortcode The shortcode of the emoji. + * @param image The image file to be uploaded, as a File or URL. + * @param options.category A category for the emoji. + * @param options.alt Text description of the emoji. + * @param options.global Whether the emoji should be visible to all users (requires `emoji` permission). + * @return Emoji + */ + public uploadEmoji( + shortcode: string, + image: File | URL, + options?: Partial<{ + alt: string; + category: string; + global: boolean; + }>, + extra?: RequestInit, + ): Promise> { + return this.postForm( + "/api/v1/emojis", + { + shortcode, + element: image instanceof File ? image : image.toString(), + ...options, + }, + extra, + ); + } + /** * POST /api/v2/media *