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:
@@ -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
|
* Map error codes to HTTP status codes
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
handleGetOrder,
|
handleGetOrder,
|
||||||
handleDeleteOrder,
|
handleDeleteOrder,
|
||||||
handleGetBalance,
|
handleGetBalance,
|
||||||
|
handleGetOsImages,
|
||||||
} from './handlers/provision';
|
} from './handlers/provision';
|
||||||
import { handleProvisionQueue } from './handlers/queue';
|
import { handleProvisionQueue } from './handlers/queue';
|
||||||
import type { ProvisionQueueMessage } from './types';
|
import type { ProvisionQueueMessage } from './types';
|
||||||
@@ -113,6 +114,10 @@ export default {
|
|||||||
return handleGetBalance(request, env, corsHeaders);
|
return handleGetBalance(request, env, corsHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path === '/api/provision/images' && request.method === 'GET') {
|
||||||
|
return handleGetOsImages(env, corsHeaders);
|
||||||
|
}
|
||||||
|
|
||||||
// Dynamic route: /api/provision/orders/:id
|
// Dynamic route: /api/provision/orders/:id
|
||||||
const orderMatch = path.match(/^\/api\/provision\/orders\/([a-zA-Z0-9-]+)$/);
|
const orderMatch = path.match(/^\/api\/provision\/orders\/([a-zA-Z0-9-]+)$/);
|
||||||
if (orderMatch) {
|
if (orderMatch) {
|
||||||
|
|||||||
@@ -371,6 +371,13 @@ export class ProvisioningService {
|
|||||||
return { balance_krw: balance, user_id: user.id };
|
return { balance_krw: balance, user_id: user.id };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get available OS images
|
||||||
|
*/
|
||||||
|
async getOsImages() {
|
||||||
|
return this.repo.getActiveOsImages();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a server (terminate) - requires telegram_id for authorization
|
* Delete a server (terminate) - requires telegram_id for authorization
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user