UNPKG

node-catbox

Version:

A library for interacting with Catbox.moe written in TypeScript.

169 lines (165 loc) 4.5 kB
type UploadURLOptions = { /** * Direct URL of the file to upload */ url: string; }; type UploadFileOptions = { /** * Path to the file to upload */ path: string; }; type DeleteFilesOptions = { /** * Array of existing file names (including extension) to delete */ files: string[]; }; type CreateAlbumOptions = { /** * Title of the album */ title: string; /** * Description of the album */ description: string; /** * Names of existing files that the album should contain */ files?: string[]; }; type EditAlbumOptions = CreateAlbumOptions & { /** * ID of the album */ id: string; }; type AddFilesToAlbumOptions = { /** * ID of the album */ id: string; /** * Names of existing files to add to the album */ files: string[]; }; type RemoveFilesFromAlbumOptions = { /** * ID of the album */ id: string; /** * Names of existing files to remove from the album */ files: string[]; }; type DeleteAlbumOptions = { /** * ID of the album */ id: string; }; declare class Catbox { private _userHash?; /** * Creates a new {@link Catbox} instance * @param userHash Optional user hash */ constructor(userHash?: string); /** * The user hash, if available */ get userHash(): string | undefined; /** * Sets the user hash for this instance * @param userHash Your account's user hash * @see https://catbox.moe/user/manage.php */ setUserHash(userHash: string): void; /** * Uploads a file via direct URL to Catbox.moe * * Files uploaded while a `userHash` is provided will be tied to your account. * @param options Options * @returns The uploaded file URL */ uploadURL(options: UploadURLOptions): Promise<string>; /** * Uploads a file via its path to Catbox.moe * * Files uploaded while a `userHash` is provided will be tied to your account. * @param options Options * @returns The uploaded file URL */ uploadFile(options: UploadFileOptions): Promise<string>; /** * Deletes files from the user account * @param options Options * @returns `true` if files have been deleted successfully */ deleteFiles(options: DeleteFilesOptions): Promise<boolean>; /** * Creates an album * @param options Options * @returns The album URL */ createAlbum(options: CreateAlbumOptions): Promise<string>; /** * Edits an existing album * * Values are treated as direct input. For example omitting the description will remove the album's description and supplying a new array of files will change the album's files. * * Consider using the less-destructive {@link addFilesToAlbum} or {@link removeFilesFromAlbum} methods if you wish to only modify album contents. * @param options Options * @returns The album URL */ editAlbum(options: EditAlbumOptions): Promise<string>; /** * Adds existing files to an album * @param options Options * @returns The album URL */ addFilesToAlbum(options: AddFilesToAlbumOptions): Promise<string>; /** * Removes files from an album * @param id ID of the album to add files to * @param files Files to remove from the album * @returns The album URL */ removeFilesFromAlbum(options: RemoveFilesFromAlbumOptions): Promise<string>; /** * Deletes an album * @param id ID of the album to delete * @returns `true` if the album was deleted or if the album doesn't exist */ removeAlbum(options: DeleteAlbumOptions): Promise<boolean>; private _doRequest; } type UploadOptions = { /** * Path to the file to upload */ path: string; /** * Duration before the file is deleted, defaults to `1h` */ duration?: '1h' | '12h' | '24h' | '72h' | string & {}; }; declare class Litterbox { /** * Creates a new {@link Litterbox} instance */ constructor(); /** * Uploads a file temporarily to Litterbox * @param options Options * @returns The uploaded file URL */ upload(options: UploadOptions): Promise<string>; } declare const kCatboxRequestCreate: unique symbol; declare const kLitterboxRequestCreate: unique symbol; export { Catbox, Litterbox, kCatboxRequestCreate, kLitterboxRequestCreate };