Edits history of script submission #20375 for ' License images (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * License images
     * This endpoint gets licenses for one or more images. You must specify the image IDs in the body parameter and other details like the format, size, and subscription ID either in the query parameter or with each image ID in the body parameter. Values in the body parameter override values in the query parameters. The download links in the response are valid for 8 hours.
     */
    export async function main(
      auth: Shutterstock,
      subscription_id: string | undefined,
      format: "eps" | "jpg" | undefined,
      size: "small" | "medium" | "huge" | "vector" | "custom" | undefined,
      search_id: string | undefined,
      body: {
        images:
          | {
              auth_cookie?: { name: string; value: string };
              editorial_acknowledgement?: false | true;
              format?: "jpg";
              image_id: string;
              metadata?: {};
              price?: number;
              search_id?: string;
              show_modal?: false | true;
              size?: "small" | "medium" | "huge" | "custom";
              custom_dimensions?: { height?: number; width?: number };
              subscription_id?: string;
              verification_code?: string;
            }
          | {
              auth_cookie?: { name: string; value: string };
              editorial_acknowledgement?: false | true;
              format?: "eps";
              image_id: string;
              metadata?: {};
              price?: number;
              search_id?: string;
              show_modal?: false | true;
              size?: "vector";
              subscription_id?: string;
              verification_code?: string;
            }[];
      },
    ) {
      const url = new URL(`https://api.shutterstock.com/v2/images/licenses`);
      for (const [k, v] of [
        ["subscription_id", subscription_id],
        ["format", format],
        ["size", size],
        ["search_id", search_id],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        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 235 days ago