//native
type Fly = {
token: string;
};
/**
* Get Regions
* List all regions on the platform with their current Machine capacity.
*/
export async function main(
auth: Fly,
size: string | undefined,
cpu_kind: string | undefined,
memory_mb: string | undefined,
cpus: string | undefined,
gpus: string | undefined,
gpu_kind: string | undefined,
) {
const url = new URL(`https://api.machines.dev/v1/platform/regions`);
for (const [k, v] of [
["size", size],
["cpu_kind", cpu_kind],
["memory_mb", memory_mb],
["cpus", cpus],
["gpus", gpus],
["gpu_kind", gpu_kind],
]) {
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 235 days ago