feat(client): Add Emoji API

This commit is contained in:
Jesse Wierzbinski 2024-11-28 10:41:20 +01:00
parent 2289ddce11
commit 122842c00e
No known key found for this signature in database
3 changed files with 89 additions and 1 deletions

View file

@ -1,4 +1,5 @@
export type Emoji = { export type Emoji = {
id: string;
shortcode: string; shortcode: string;
static_url: string; static_url: string;
url: string; url: string;

View file

@ -8,7 +8,7 @@ export type VersiaRole = {
icon: string | null; icon: string | null;
}; };
// Last updated: 2024-06-07 // Last updated: 2024-11-28
export enum RolePermission { export enum RolePermission {
ManageNotes = "notes", ManageNotes = "notes",
ManageOwnNotes = "owner:note", ManageOwnNotes = "owner:note",

View file

@ -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<Output<void>> {
return this.delete<void>(`/api/v1/emojis/${id}`, undefined, extra);
}
/** /**
* DELETE /api/v1/statuses/:id/reactions/:emoji * DELETE /api/v1/statuses/:id/reactions/:emoji
* *
@ -903,6 +913,16 @@ export class Client extends BaseClient {
return this.get<string[]>(`/api/v1/domain_blocks?${params}`); return this.get<string[]>(`/api/v1/domain_blocks?${params}`);
} }
/**
* GET /api/v1/emojis/:id
*
* @param id The emoji ID.
* @return Emoji.
*/
public getEmoji(id: string, extra?: RequestInit): Promise<Output<Emoji>> {
return this.get<Emoji>(`/api/v1/emojis/${id}`, extra);
}
/** /**
* GET /api/v1/endorsements * 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<Output<Emoji>> {
return this.patchForm<Emoji>(
`/api/v1/emojis/${id}`,
{
...options,
image: undefined,
element:
options.image instanceof File
? options.image
: options.image?.toString(),
},
extra,
);
}
// TODO: updateFilter // 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<Output<Emoji>> {
return this.postForm<Emoji>(
"/api/v1/emojis",
{
shortcode,
element: image instanceof File ? image : image.toString(),
...options,
},
extra,
);
}
/** /**
* POST /api/v2/media * POST /api/v2/media
* *