UNPKG

node-catbox

Version:

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

203 lines (199 loc) 5.65 kB
type UploadURLOptions = { /** * Direct URL of the file to upload */ url: string; }; type UploadFileOptions$1 = { /** * Path to the file to upload */ path: string; }; type UploadFileStreamOptions$1 = { stream: ReadableStream | AsyncIterable<any>; filename: 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({ url }: 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({ path }: UploadFileOptions$1): Promise<string>; uploadFileStream({ stream, filename }: UploadFileStreamOptions$1): Promise<string>; /** * Deletes files from the user account * @param options Options * @returns `true` if files have been deleted successfully */ deleteFiles({ files }: DeleteFilesOptions): Promise<boolean>; /** * Creates an album * @param options Options * @returns The album URL */ createAlbum({ title, description, files }: 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({ id, title, description, files }: EditAlbumOptions): Promise<string>; /** * Adds existing files to an album * @param options Options * @returns The album URL */ addFilesToAlbum({ id, files }: AddFilesToAlbumOptions): Promise<string>; /** * Removes files from an album * @param options Options * @returns The album URL */ removeFilesFromAlbum({ id, files }: RemoveFilesFromAlbumOptions): Promise<string>; /** * Deletes an album * @param options Options * @returns `true` if the album was deleted or if the album doesn't exist */ removeAlbum({ id }: DeleteAlbumOptions): Promise<boolean>; private _doRequest; } /** * @deprecated Use `UploadFileOptions` instead. */ type UploadOptions = UploadFileOptions; type UploadFileOptions = { /** * Path to the file to upload */ path: string; /** * Duration before the file is deleted, defaults to `1h` */ duration?: typeof acceptedDurations[number] | FileLifetime; }; type UploadFileStreamOptions = { stream: ReadableStream | AsyncIterable<any>; filename: string; /** * Duration before the file is deleted, defaults to `1h` */ duration?: typeof acceptedDurations[number] | FileLifetime; }; declare const acceptedDurations: readonly ["1h", "12h", "24h", "72h"]; declare const enum FileLifetime { OneHour = "1h", TwelveHours = "12h", OneDay = "24h", ThreeDays = "72h" } declare class Litterbox { /** * Creates a new {@link Litterbox} instance */ constructor(); /** * @deprecated Use `uploadFile` instead. * * Uploads a file temporarily to Litterbox * @param options Options * @returns The uploaded file URL */ upload({ path, duration }: UploadOptions): Promise<string>; /** * Uploads a file temporarily to Litterbox * @param options Options * @returns The uploaded file URL */ uploadFile({ path, duration }: UploadFileOptions): Promise<string>; uploadFileStream({ stream, filename, duration }: UploadFileStreamOptions): Promise<string>; private isDurationValid; private _doRequest; } declare const kCatboxRequestCreate: unique symbol; declare const kLitterboxRequestCreate: unique symbol; export { Catbox, FileLifetime, Litterbox, kCatboxRequestCreate, kLitterboxRequestCreate };