forked from wrenn/wrenn
Added basic frontend (#1)
Reviewed-on: wrenn/sandbox#1 Co-authored-by: pptx704 <rafeed@omukk.dev> Co-committed-by: pptx704 <rafeed@omukk.dev>
This commit is contained in:
66
frontend/src/lib/api/capsules.ts
Normal file
66
frontend/src/lib/api/capsules.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { apiFetch, type ApiResult } from '$lib/api/client';
|
||||
|
||||
export type Capsule = {
|
||||
id: string;
|
||||
status: string;
|
||||
template: string;
|
||||
vcpus: number;
|
||||
memory_mb: number;
|
||||
timeout_sec: number;
|
||||
guest_ip?: string;
|
||||
host_ip?: string;
|
||||
created_at: string;
|
||||
started_at?: string;
|
||||
last_active_at?: string;
|
||||
last_updated: string;
|
||||
};
|
||||
|
||||
|
||||
export async function listCapsules(): Promise<ApiResult<Capsule[]>> {
|
||||
return apiFetch('GET', '/api/v1/sandboxes');
|
||||
}
|
||||
|
||||
export type CreateCapsuleParams = {
|
||||
template?: string;
|
||||
vcpus?: number;
|
||||
memory_mb?: number;
|
||||
timeout_sec?: number;
|
||||
};
|
||||
|
||||
export async function createCapsule(params: CreateCapsuleParams): Promise<ApiResult<Capsule>> {
|
||||
return apiFetch('POST', '/api/v1/sandboxes', params);
|
||||
}
|
||||
|
||||
export async function pauseCapsule(id: string): Promise<ApiResult<Capsule>> {
|
||||
return apiFetch('POST', `/api/v1/sandboxes/${id}/pause`);
|
||||
}
|
||||
|
||||
export async function resumeCapsule(id: string): Promise<ApiResult<Capsule>> {
|
||||
return apiFetch('POST', `/api/v1/sandboxes/${id}/resume`);
|
||||
}
|
||||
|
||||
export async function destroyCapsule(id: string): Promise<ApiResult<void>> {
|
||||
return apiFetch('DELETE', `/api/v1/sandboxes/${id}`);
|
||||
}
|
||||
|
||||
export type Snapshot = {
|
||||
name: string;
|
||||
type: string;
|
||||
vcpus?: number;
|
||||
memory_mb?: number;
|
||||
size_bytes: number;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export async function createSnapshot(sandboxId: string, name?: string): Promise<ApiResult<Snapshot>> {
|
||||
return apiFetch('POST', '/api/v1/snapshots', { sandbox_id: sandboxId, name });
|
||||
}
|
||||
|
||||
export async function listSnapshots(typeFilter?: string): Promise<ApiResult<Snapshot[]>> {
|
||||
const url = typeFilter ? `/api/v1/snapshots?type=${typeFilter}` : '/api/v1/snapshots';
|
||||
return apiFetch('GET', url);
|
||||
}
|
||||
|
||||
export async function deleteSnapshot(name: string): Promise<ApiResult<void>> {
|
||||
return apiFetch('DELETE', `/api/v1/snapshots/${name}`);
|
||||
}
|
||||
Reference in New Issue
Block a user