初始提交:OCI 面板前端(含 GenAI 网关一期)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { mockBootVolumes } from './mock'
|
||||
import { mockOn, mocked, request } from './request'
|
||||
import type { BootVolume, UpdateBootVolumeRequest } from '@/types/api'
|
||||
|
||||
export function listBootVolumes(
|
||||
cfgId: number,
|
||||
availabilityDomain?: string,
|
||||
compartmentId?: string,
|
||||
region?: string,
|
||||
): Promise<BootVolume[]> {
|
||||
if (mockOn) return mocked(compartmentId ? [] : (mockBootVolumes[cfgId] ?? []))
|
||||
return request(`/oci-configs/${cfgId}/boot-volumes`, {
|
||||
query: { availabilityDomain, compartmentId, region },
|
||||
})
|
||||
}
|
||||
|
||||
export function getBootVolume(
|
||||
cfgId: number,
|
||||
bootVolumeId: string,
|
||||
region?: string,
|
||||
): Promise<BootVolume> {
|
||||
if (mockOn) {
|
||||
const found = Object.values(mockBootVolumes)
|
||||
.flat()
|
||||
.find((b) => b.id === bootVolumeId)
|
||||
return found ? mocked(found) : Promise.reject(new Error('引导卷不存在'))
|
||||
}
|
||||
return request(`/oci-configs/${cfgId}/boot-volumes/${encodeURIComponent(bootVolumeId)}`, {
|
||||
query: { region },
|
||||
})
|
||||
}
|
||||
|
||||
export function updateBootVolume(
|
||||
cfgId: number,
|
||||
bootVolumeId: string,
|
||||
body: UpdateBootVolumeRequest,
|
||||
region?: string,
|
||||
): Promise<BootVolume> {
|
||||
if (mockOn) {
|
||||
const base = Object.values(mockBootVolumes).flat()[0]
|
||||
return mocked({ ...base, ...body }, 700)
|
||||
}
|
||||
return request(`/oci-configs/${cfgId}/boot-volumes/${encodeURIComponent(bootVolumeId)}`, {
|
||||
method: 'PUT',
|
||||
body: { region: region ?? '', ...body },
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteBootVolume(
|
||||
cfgId: number,
|
||||
bootVolumeId: string,
|
||||
region?: string,
|
||||
): Promise<void> {
|
||||
if (mockOn) return mocked(undefined)
|
||||
return request(`/oci-configs/${cfgId}/boot-volumes/${encodeURIComponent(bootVolumeId)}`, {
|
||||
method: 'DELETE',
|
||||
query: { region },
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user