UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

194 lines (193 loc) 4.51 kB
/** * A strategy for posting messages to Mastodon. */ export class MastodonStrategy { /** * Creates a new instance. * @param {MastodonOptions} options Options for the instance. * @throws {Error} When options are missing. */ constructor(options: MastodonOptions); /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Maximum length of a Mastodon post in characters (default instance limit). * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * Calculates the length of a message according to Mastodon's algorithm. * All characters, including URLs, are counted as their actual length. * @param {string} message The message to calculate the length of. * @returns {number} The calculated length of the message. */ calculateMessageLength(message: string): number; /** * Posts a message to Mastodon. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<Object>} A promise that resolves with the post data. */ post(message: string, postOptions?: PostOptions): Promise<Object>; /** * Extracts a URL from a Mastodon API response. * @param {MastodonPostResponse} response The response from the Mastodon API post request. * @returns {string} The URL for the Mastodon post. */ getUrlFromResponse(response: MastodonPostResponse): string; #private; } export type PostOptions = import("../types.js").PostOptions; export type MastodonOptions = { /** * The access token for the Mastodon account. */ accessToken: string; /** * The host for the Mastodon instance. */ host: string; }; export type MastodonErrorResponse = { /** * The error message returned by the Mastodon API. */ error: string; }; export type MastodonMediaSize = { /** * The width of the media. */ width: number; /** * The height of the media. */ height: number; /** * The size as string (e.g. "640x480"). */ size: string; /** * The aspect ratio. */ aspect: number; }; export type MastodonMediaFocus = { /** * The x coordinate of the focus point. */ x: number; /** * The y coordinate of the focus point. */ y: number; }; export type MastodonMediaResponse = { /** * The unique identifier of the uploaded media */ id: string; /** * The type of media (e.g. "image") */ type: string; /** * The URL of the media */ url: string | null; /** * The URL of the preview image */ preview_url: string; /** * The remote URL of the media if applicable */ remote_url: string | null; /** * The text URL of the media */ text_url: string; /** * Metadata about the media */ meta: { focus: MastodonMediaFocus; original: MastodonMediaSize; small: MastodonMediaSize; }; /** * Alt text description of the media */ description: string; /** * The blurhash string for the media */ blurhash: string; }; export type MastodonMediaAttachment = { /** * The unique identifier of the media attachment */ id: string; /** * The type of media (e.g. "image") */ type: string; /** * The URL of the full-size media */ url: string | null; /** * The URL of the preview image */ preview_url: string; /** * The remote URL of the media if hosted elsewhere */ remote_url: string | null; /** * The text URL of the media */ text_url: string | null; /** * Metadata about the media attachment */ meta: Object; /** * Alt text description of the media */ description: string; /** * The blurhash string for generating a placeholder */ blurhash: string; }; export type MastodonPostResponse = { /** * The unique identifier of the post. */ id: string; /** * The URI of the post. */ uri: string; /** * The URL of the post. */ url: string; /** * The content of the post. */ content: string; };