mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
Initial release v0.2.5
This commit is contained in:
commit
bbf66c259b
158 files changed
+37115
No files matched your search
@@ -0,0 +1,101 @@
|
||||
import axios from 'axios'
|
||||
import type {
|
||||
SettingsResponse,
|
||||
UpdateSettingsRequest,
|
||||
OpenCodeConfig,
|
||||
OpenCodeConfigResponse,
|
||||
CreateOpenCodeConfigRequest,
|
||||
UpdateOpenCodeConfigRequest
|
||||
} from './types/settings'
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5001'
|
||||
|
||||
export const settingsApi = {
|
||||
getSettings: async (userId = 'default'): Promise<SettingsResponse> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
updateSettings: async (
|
||||
updates: UpdateSettingsRequest,
|
||||
userId = 'default'
|
||||
): Promise<SettingsResponse> => {
|
||||
const { data } = await axios.patch(`${API_BASE_URL}/api/settings`, updates, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
resetSettings: async (userId = 'default'): Promise<SettingsResponse> => {
|
||||
const { data } = await axios.delete(`${API_BASE_URL}/api/settings`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
getOpenCodeConfigs: async (userId = 'default'): Promise<OpenCodeConfigResponse> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings/opencode-configs`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
createOpenCodeConfig: async (
|
||||
request: CreateOpenCodeConfigRequest,
|
||||
userId = 'default'
|
||||
): Promise<OpenCodeConfig> => {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-configs`, request, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
},
|
||||
|
||||
updateOpenCodeConfig: async (
|
||||
configName: string,
|
||||
request: UpdateOpenCodeConfigRequest,
|
||||
userId = 'default'
|
||||
): Promise<OpenCodeConfig> => {
|
||||
const { data } = await axios.put(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}`,
|
||||
request,
|
||||
{ params: { userId } }
|
||||
)
|
||||
return data
|
||||
},
|
||||
|
||||
deleteOpenCodeConfig: async (
|
||||
configName: string,
|
||||
userId = 'default'
|
||||
): Promise<boolean> => {
|
||||
await axios.delete(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}`,
|
||||
{ params: { userId } }
|
||||
)
|
||||
return true
|
||||
},
|
||||
|
||||
setDefaultOpenCodeConfig: async (
|
||||
configName: string,
|
||||
userId = 'default'
|
||||
): Promise<OpenCodeConfig> => {
|
||||
const { data } = await axios.post(
|
||||
`${API_BASE_URL}/api/settings/opencode-configs/${encodeURIComponent(configName)}/set-default`,
|
||||
{},
|
||||
{ params: { userId } }
|
||||
)
|
||||
return data
|
||||
},
|
||||
|
||||
getDefaultOpenCodeConfig: async (userId = 'default'): Promise<OpenCodeConfig | null> => {
|
||||
try {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings/opencode-configs/default`, {
|
||||
params: { userId },
|
||||
})
|
||||
return data
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user