Edits history of script submission #17180 for ' Update an image (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Update an image
     * Updates a private image that you have permission to `read_write`.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      imageId: string,
      body: {
        capabilities?: string[];
        created?: string;
        created_by?: string;
        deprecated?: false | true;
        description?: string;
        eol?: string;
        expiry?: string;
        id?: string;
        is_public?: false | true;
        label?: string;
        regions?: {
          region?: string;
          status?:
            | "available"
            | "creating"
            | "pending"
            | "pending deletion"
            | "pending replication"
            | "replicating";
        }[];
        size?: number;
        status?: "available" | "creating" | "pending_upload";
        tags?: string[];
        total_size?: number;
        type?: "manual" | "automatic";
        updated?: string;
        vendor?: string;
      },
    ) {
      const url = new URL(`https://api.linode.com/${apiVersion}/images/${imageId}`);
    
      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 235 days ago