feat: add GET /api/provision/images endpoint

- Add handleGetOsImages handler in provision.ts
- Add getOsImages method in ProvisioningService
- Add route in index.ts
- Returns key, name, family, is_default for each OS image

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-28 10:35:16 +09:00
parent 3c420d2841
commit 1c65c02045
3 changed files with 44 additions and 0 deletions

View File

@@ -338,6 +338,38 @@ export async function handleGetBalance(
}
}
/**
* GET /api/provision/images
* Get available OS images
*/
export async function handleGetOsImages(
env: Env,
corsHeaders: Record<string, string>
): Promise<Response> {
try {
const provisioningService = new ProvisioningService(
env,
env.DB,
env.USER_DB
);
const images = await provisioningService.getOsImages();
// Return simplified image list for API consumers
const response = images.map((img) => ({
key: img.key,
name: img.name,
family: img.family,
is_default: img.is_default === 1,
}));
return createSuccessResponse({ images: response }, 200, corsHeaders);
} catch (error) {
console.error('[handleGetOsImages] Error:', error);
return createErrorResponse('Internal server error', 500, undefined, corsHeaders);
}
}
/**
* Map error codes to HTTP status codes
*/