Edits history of script submission #11044 for ' Update an Image (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update an Image
     * To update an image, send a `PUT` request to `/v2/images/$IMAGE_ID`.
    Set the `name` attribute to the new value you would like to use.
    For custom images, the `description` and `distribution` attributes may also be updated.
    
     */
    export async function main(
      auth: Digitalocean,
      image_id: string,
      body: {
        name?: string;
        distribution?:
          | "Arch Linux"
          | "CentOS"
          | "CoreOS"
          | "Debian"
          | "Fedora"
          | "Fedora Atomic"
          | "FreeBSD"
          | "Gentoo"
          | "openSUSE"
          | "RancherOS"
          | "Rocky Linux"
          | "Ubuntu"
          | "Unknown";
        description?: string;
      },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/images/${image_id}`);
    
      const response = await fetch(url, {
        method: "PUT",
        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 537 days ago