mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-09-05 23:47:33 +08:00
功能: 前端新增一键部署 API 类型与函数
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { http, type ApiEnvelope, unwrapApiEnvelope } from './http'
|
import { http, type ApiEnvelope, unwrapApiEnvelope } from './http'
|
||||||
import type { NodeSummary, DirEntry } from '../types/nodes'
|
import type { NodeSummary, DirEntry, BatchCreateResult, InstallTokenInput, InstallTokenResult } from '../types/nodes'
|
||||||
|
|
||||||
export async function listNodes() {
|
export async function listNodes() {
|
||||||
const response = await http.get<ApiEnvelope<NodeSummary[]>>('/nodes')
|
const response = await http.get<ApiEnvelope<NodeSummary[]>>('/nodes')
|
||||||
@@ -30,3 +30,33 @@ export async function listNodeDirectory(nodeId: number, path: string) {
|
|||||||
const response = await http.get<ApiEnvelope<DirEntry[]>>(`/nodes/${nodeId}/fs/list`, { params: { path } })
|
const response = await http.get<ApiEnvelope<DirEntry[]>>(`/nodes/${nodeId}/fs/list`, { params: { path } })
|
||||||
return unwrapApiEnvelope(response.data)
|
return unwrapApiEnvelope(response.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function batchCreateNodes(names: string[]) {
|
||||||
|
const response = await http.post<ApiEnvelope<BatchCreateResult[]>>('/nodes/batch', { names })
|
||||||
|
return unwrapApiEnvelope(response.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createInstallToken(nodeId: number, input: InstallTokenInput) {
|
||||||
|
const response = await http.post<ApiEnvelope<InstallTokenResult>>(
|
||||||
|
`/nodes/${nodeId}/install-tokens`, input,
|
||||||
|
)
|
||||||
|
return unwrapApiEnvelope(response.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function rotateNodeToken(nodeId: number) {
|
||||||
|
const response = await http.post<ApiEnvelope<{ newToken: string }>>(
|
||||||
|
`/nodes/${nodeId}/rotate-token`,
|
||||||
|
)
|
||||||
|
return unwrapApiEnvelope(response.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchScriptPreview(
|
||||||
|
nodeId: number,
|
||||||
|
params: { mode: string; arch: string; agentVersion: string; downloadSrc: string },
|
||||||
|
) {
|
||||||
|
const response = await http.get<string>(`/nodes/${nodeId}/install-script-preview`, {
|
||||||
|
params,
|
||||||
|
responseType: 'text',
|
||||||
|
})
|
||||||
|
return response.data
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,3 +18,27 @@ export interface DirEntry {
|
|||||||
isDir: boolean
|
isDir: boolean
|
||||||
size: number
|
size: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type InstallMode = 'systemd' | 'docker' | 'foreground'
|
||||||
|
export type InstallArch = 'amd64' | 'arm64' | 'auto'
|
||||||
|
export type InstallSource = 'github' | 'ghproxy'
|
||||||
|
|
||||||
|
export interface BatchCreateResult {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InstallTokenInput {
|
||||||
|
mode: InstallMode
|
||||||
|
arch: InstallArch
|
||||||
|
agentVersion: string
|
||||||
|
downloadSrc: InstallSource
|
||||||
|
ttlSeconds: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InstallTokenResult {
|
||||||
|
installToken: string
|
||||||
|
expiresAt: string
|
||||||
|
url: string
|
||||||
|
composeUrl: string
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user