//native
type Digitalocean = {
token: string;
};
/**
* Initiate A Block Storage Action By Volume Name
* To initiate an action on a block storage volume by Name, send a POST request to
`~/v2/volumes/actions`.
*/
export async function main(
auth: Digitalocean,
per_page: string | undefined,
page: string | undefined,
body:
| ({
type: "attach" | "detach" | "resize";
region?:
| "ams1"
| "ams2"
| "ams3"
| "blr1"
| "fra1"
| "lon1"
| "nyc1"
| "nyc2"
| "nyc3"
| "sfo1"
| "sfo2"
| "sfo3"
| "sgp1"
| "tor1"
| "syd1";
} & { droplet_id: number; tags?: string[] })
| ({
type: "attach" | "detach" | "resize";
region?:
| "ams1"
| "ams2"
| "ams3"
| "blr1"
| "fra1"
| "lon1"
| "nyc1"
| "nyc2"
| "nyc3"
| "sfo1"
| "sfo2"
| "sfo3"
| "sgp1"
| "tor1"
| "syd1";
} & { droplet_id: number }),
) {
const url = new URL(`https://api.digitalocean.com/v2/volumes/actions`);
for (const [k, v] of [
["per_page", per_page],
["page", page],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
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 536 days ago