Edits history of script submission #23099 for ' Create R2 Bucket (cloudflare)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create R2 Bucket
     * Create an R2 bucket in the account, optionally with a location hint.
     */
    export async function main(
      auth: RT.Cloudflare,
      name: string,
      location_hint: "apac" | "eeur" | "enam" | "weur" | "wnam" | "oc" | undefined
    ) {
      const response = await fetch(
        `https://api.cloudflare.com/client/v4/accounts/${auth.account_id}/r2/buckets`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({ name, locationHint: location_hint ?? undefined }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 4 hours ago