Edits history of script submission #12523 for ' Get Texture Generation by ID (leonardoai)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Leonardoai = {
      apiKey: string;
    };
    /**
     * Get Texture Generation by ID
     * This endpoint gets the specific texture generation.
     */
    export async function main(
      auth: Leonardoai,
      id: string,
      offset: string | undefined,
      limit: string | undefined,
      body: { id?: string },
    ) {
      const url = new URL(
        `https://cloud.leonardo.ai/api/rest/v1/generations-texture/${id}`,
      );
      for (const [k, v] of [
        ["offset", offset],
        ["limit", limit],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago