UNPKG

wombo-dream-api

Version:
215 lines (214 loc) 7.17 kB
/// <reference types="node" /> import { AxiosInstance, AxiosRequestConfig } from 'axios'; import GoogleAuthentifier from './GoogleAuthentifier'; import { SavedTask, Task, TaskImageInputSpec, UploadResource } from './types'; import { Style } from 'util'; export declare const DEFAULT_DISPLAY_FREQ = 10; export declare const DEFAULT_CHECK_FREQ = 1000; export declare class WomboDream { authentifier: GoogleAuthentifier; apiTaskUrl: string; apiUserSuffix: string; apiTaskSuffix: string; apiShopSuffix: string; apiStyleSuffix: string; apiGallerySuffix: string; originUrl: string; uploadUrl: string; constructor(authentifier: GoogleAuthentifier, apiTaskUrl: string, apiUserSuffix: string, apiTaskSuffix: string, apiShopSuffix: string, apiStyleSuffix: string, apiGallerySuffix: string, originUrl: string, uploadUrl: string); buildApiTaskUrl(taskId: string): string; buildRawApiTaskUrl(): string; buildUploadUrl(): string; buildApiStyleUrl(): string; buildApiTaskShopUrl(taskId: string): string; buildApiGalleryUrl(taskId: string): string; buildRawApiGalleryUrl(): string; /** * Create a new HTTP request agent with custom headers for dream API * @example * ```ts * const agent = await dreamInstance.buildHttpRequestAgentForDreamApi(); * agent.get('https://app.wombo.art').then(res => console.log(res.data)); * ``` */ buildHttpRequestAgentForDreamApi(): Promise<AxiosInstance>; /** * Create a new HTTP request agent with custom headers for user API * @example * ```ts * const agent = await dreamInstance.buildHttpRequestAgentForApiUser(); * agent.post('https://app.wombo.art/api/users', {username: "myusername"}).then(res => console.log(res.data)); * ``` */ buildHttpRequestAgentForUserAPI(): Promise<AxiosInstance>; /** * Create a new HTTP request agent with custom headers * @example * ```ts * const agent = await dreamInstance.buildHttpRequestAgentForApiUser({baseURL: "https://app.wombo.art", headers: {Authorization: "Bearer 12345"}}); * agent.get('https://app.wombo.art').then(res => console.log(res.data)); * ``` */ buildHttpRequestAgent(config: AxiosRequestConfig<any>): Promise<AxiosInstance>; /** * Initialize new Task * * The Task wont start until it is configured * * @example * ```ts * dreamInstance.initTask().then(console.log); * ``` */ initTask(): Promise<Task>; /** * Configure an existing Task * * @param input_image use an image as input * @param display_freq how often the task makes intermediate renders * * @warning must be done with the same account as the task was created * * @example * ```ts * const task:Task; * dreamInstance.configureTask(task, "kitten", 34).then(console.log); * ``` */ configureTask(task: Task, prompt: string, style: number, input_image?: TaskImageInputSpec, display_freq?: number): Promise<Task>; /** * Create and configure an existing Task * * @param input_image use an image as input * @param display_freq how often the task makes intermediate renders * * @example * ```ts * dreamInstance.createTask("kitten", 34).then(console.log); * ``` */ createTask(prompt: string, style: number, input_image?: TaskImageInputSpec, display_freq?: number): Promise<Task>; /** * Fetch the current infos of a Task * * @warning must be done with the same account as the task was created * * @example * ```ts * const taskId:string; * dreamInstance.fetchTaskInfos(taskId).then(console.log); * ``` */ fetchTaskInfos(taskId: string): Promise<Task>; /** * Create a new task and generate a picture * * @param progressCallback a callback function that will be called with the progress of the Task * @param input_image use an image as input * @param display_freq how often the task makes intermediate renders * * @example * ```ts * dreamInstance.generatePicture('kitten', 34, (task) => { * console.log(task.state, 'stage', task.photo_url_list.length); * }) * .then((task) => console.log(task?.result.final)) * .catch(console.error); * ``` */ generatePicture(prompt: string, style: number, progressCallback?: (task: Task) => void, input_image?: TaskImageInputSpec, checkFrequency?: number, display_freq?: number): Promise<Task>; /** * Upload an image for later use * * @warning jpg/jpeg are the only supported image formats * * @example * ```ts * dreamInstance.uploadImage(fs.readFileSync('./image.jpg')).then(console.log); * ``` */ uploadImage(bufferedImage: Buffer): Promise<UploadResource>; /** * Fetch all available styles * * @example * ```ts * dreamInstance.fetchStyles().then(console.log); * ``` */ fetchStyles(): Promise<Array<Style>>; /** * Fetch shop url from task id * * @warning must be done with the same account as the task was created * * @example * ```ts * const taskId:string; * dreamInstance.fetchTaskShopUrl(taskId).then(console.log); * ``` */ fetchTaskShopUrl(taskId: string): Promise<String>; /** * Save task to the gallery * * @warning must be done with the same account as the task was created * @warning you must be logged as a user to use it * * @example * ```ts * const taskId:string; * dreamInstance.saveTaskToGallery(taskId, "wonderful kitty").then(console.log); * ``` */ saveTaskToGallery(taskId: string, name?: string, isPublic?: boolean, isPromptVisible?: boolean): Promise<SavedTask>; /** * Fetch a gallery saved task * * @warning task_id != task_gallery_id * @warning you must be logged as a user to use it * * @example * ```ts * const taskGalleryId:number; * dreamInstance.fetchGalleryTask(taskGalleryId).then(console.log); * ``` */ fetchGalleryTask(taskGalleryId: number): Promise<SavedTask>; /** * Fetch gallery saved tasks * * @warning you must be logged as a user to use it * * @example * ```ts * dreamInstance.fetchGalleryTasks().then(console.log); * ``` */ fetchGalleryTasks(): Promise<Array<SavedTask>>; /** * Fetch a gallery saved task * * @warning task_id != task_gallery_id * @warning you must be logged as a user to use it * * @example * ```ts * const taskGalleryId:number; * dreamInstance.deleteGalleryTask(taskGalleryId); * ``` */ deleteGalleryTask(taskGalleryId: number): Promise<void>; /** * Set account username * * @warning YOU NEED TO SET A USERNAME TO INTERRACT WITH GALLERY * * @example * ```ts * dreamInstance.setUsername("myusername"); * ``` */ setUsername(username: string): Promise<void>; } export default WomboDream;