Edits history of script submission #10725 for ' Create a Custom Image (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a Custom Image
     * To create a new custom image, send a POST request to /v2/images.
    The body must contain a url attribute pointing to a Linux virtual machine
    image to be imported into DigitalOcean.
    The image must be in the raw, qcow2, vhdx, vdi, or vmdk format.
    It may be compressed using gzip or bzip2 and must be smaller than 100 GB after
     being decompressed.
    
     */
    export async function main(
      auth: Digitalocean,
      body: {
        name?: string;
        distribution?:
          | "Arch Linux"
          | "CentOS"
          | "CoreOS"
          | "Debian"
          | "Fedora"
          | "Fedora Atomic"
          | "FreeBSD"
          | "Gentoo"
          | "openSUSE"
          | "RancherOS"
          | "Rocky Linux"
          | "Ubuntu"
          | "Unknown";
        description?: string;
      } & {
        url?: string;
        region?:
          | "ams1"
          | "ams2"
          | "ams3"
          | "blr1"
          | "fra1"
          | "lon1"
          | "nyc1"
          | "nyc2"
          | "nyc3"
          | "sfo1"
          | "sfo2"
          | "sfo3"
          | "sgp1"
          | "tor1"
          | "syd1";
        tags?: string[];
      },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/images`);
    
      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 537 days ago