//native
type Digitalocean = {
token: string;
};
/**
* List All Block Storage Volumes
* To list all of the block storage volumes available on your account, send a GET request to `/v2/volumes`.
*/
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,
per_page: string | undefined,
page: string | undefined,
) {
const url = new URL(`https://api.digitalocean.com/v2/volumes`);
for (const [k, v] of [
["name", name],
["region", region],
["per_page", per_page],
["page", page],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
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