//native
type Digitalocean = {
token: string;
};
/**
* Delete a Block Storage Volume by Name
* Block storage volumes may also be deleted by name by sending a DELETE request with the volume's **name** and the **region slug** for the region it is located in as query parameters to `/v2/volumes?name=$VOLUME_NAME®ion=nyc1`.
No response body will be sent back, but the response code will indicate success. Specifically, the response code will be a 204, which means that the action was successful with no returned body data.
*/
export async function main(
auth: Digitalocean,
name: string | undefined,
region:
| "ams1"
| "ams2"
| "ams3"
| "blr1"
| "fra1"
| "lon1"
| "nyc1"
| "nyc2"
| "nyc3"
| "sfo1"
| "sfo2"
| "sfo3"
| "sgp1"
| "tor1"
| "syd1"
| undefined,
) {
const url = new URL(`https://api.digitalocean.com/v2/volumes`);
for (const [k, v] of [
["name", name],
["region", region],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago