mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-15 08:46:58 +08:00
fix: add web/src/lib/api/ split files and fix .gitignore
The .gitignore had a Python-inherited `lib/` rule that blocked the entire web/src/lib/api/ directory from being tracked. The original api.ts was a file (not matched), but the split created a directory inside lib/ which was ignored. Remove the `lib/` gitignore rule and add the api module split files that were missing from the previous commit.
This commit is contained in:
72
web/src/lib/api/strategies.ts
Normal file
72
web/src/lib/api/strategies.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import type {
|
||||
Strategy,
|
||||
StrategyConfig,
|
||||
} from '../../types'
|
||||
import { API_BASE, httpClient } from './helpers'
|
||||
|
||||
export const strategyApi = {
|
||||
async getStrategies(): Promise<Strategy[]> {
|
||||
const result = await httpClient.get<{ strategies: Strategy[] }>(`${API_BASE}/strategies`)
|
||||
if (!result.success) throw new Error('获取策略列表失败')
|
||||
const strategies = result.data?.strategies
|
||||
return Array.isArray(strategies) ? strategies : []
|
||||
},
|
||||
|
||||
async getStrategy(strategyId: string): Promise<Strategy> {
|
||||
const result = await httpClient.get<Strategy>(`${API_BASE}/strategies/${strategyId}`)
|
||||
if (!result.success) throw new Error('获取策略失败')
|
||||
return result.data!
|
||||
},
|
||||
|
||||
async getActiveStrategy(): Promise<Strategy> {
|
||||
const result = await httpClient.get<Strategy>(`${API_BASE}/strategies/active`)
|
||||
if (!result.success) throw new Error('获取激活策略失败')
|
||||
return result.data!
|
||||
},
|
||||
|
||||
async getDefaultStrategyConfig(): Promise<StrategyConfig> {
|
||||
const result = await httpClient.get<StrategyConfig>(`${API_BASE}/strategies/default-config`)
|
||||
if (!result.success) throw new Error('获取默认策略配置失败')
|
||||
return result.data!
|
||||
},
|
||||
|
||||
async createStrategy(data: {
|
||||
name: string
|
||||
description: string
|
||||
config: StrategyConfig
|
||||
}): Promise<Strategy> {
|
||||
const result = await httpClient.post<Strategy>(`${API_BASE}/strategies`, data)
|
||||
if (!result.success) throw new Error('创建策略失败')
|
||||
return result.data!
|
||||
},
|
||||
|
||||
async updateStrategy(
|
||||
strategyId: string,
|
||||
data: {
|
||||
name?: string
|
||||
description?: string
|
||||
config?: StrategyConfig
|
||||
}
|
||||
): Promise<Strategy> {
|
||||
const result = await httpClient.put<Strategy>(`${API_BASE}/strategies/${strategyId}`, data)
|
||||
if (!result.success) throw new Error('更新策略失败')
|
||||
return result.data!
|
||||
},
|
||||
|
||||
async deleteStrategy(strategyId: string): Promise<void> {
|
||||
const result = await httpClient.delete(`${API_BASE}/strategies/${strategyId}`)
|
||||
if (!result.success) throw new Error('删除策略失败')
|
||||
},
|
||||
|
||||
async activateStrategy(strategyId: string): Promise<Strategy> {
|
||||
const result = await httpClient.post<Strategy>(`${API_BASE}/strategies/${strategyId}/activate`)
|
||||
if (!result.success) throw new Error('激活策略失败')
|
||||
return result.data!
|
||||
},
|
||||
|
||||
async duplicateStrategy(strategyId: string): Promise<Strategy> {
|
||||
const result = await httpClient.post<Strategy>(`${API_BASE}/strategies/${strategyId}/duplicate`)
|
||||
if (!result.success) throw new Error('复制策略失败')
|
||||
return result.data!
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user