//native
type Digitalocean = {
token: string;
};
/**
* Create a New Block Storage Volume
* To create a new volume, send a POST request to `/v2/volumes`. Optionally, a `filesystem_type` attribute may be provided in order to automatically format the volume's filesystem. Pre-formatted volumes are automatically mounted when attached to Ubuntu, Debian, Fedora, Fedora Atomic, and CentOS Droplets created on or after April 26, 2018. Attaching pre-formatted volumes to Droplets without support for auto-mounting is not recommended.
*/
export async function main(
auth: Digitalocean,
body: {
id?: string;
droplet_ids?: number[];
name?: string;
description?: string;
size_gigabytes?: number;
created_at?: string;
tags?: string[];
} & { snapshot_id?: string } & { filesystem_type?: string } & {
region:
| "ams1"
| "ams2"
| "ams3"
| "blr1"
| "fra1"
| "lon1"
| "nyc1"
| "nyc2"
| "nyc3"
| "sfo1"
| "sfo2"
| "sfo3"
| "sgp1"
| "tor1"
| "syd1";
filesystem_label?: string & {};
},
) {
const url = new URL(`https://api.digitalocean.com/v2/volumes`);
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