Initial commit
This commit is contained in:
40
src/services/moduleService.ts
Normal file
40
src/services/moduleService.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { Module, ModuleAction } from '@/types/module'
|
||||
|
||||
const API_BASE = '/modules'
|
||||
|
||||
export async function fetchModules(): Promise<Module[]> {
|
||||
const response = await fetch(`${API_BASE}/list`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch modules: ${response.statusText}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return data.modules || []
|
||||
}
|
||||
|
||||
export async function manageModule(handle: string, action: ModuleAction): Promise<{ message?: string; error?: string }> {
|
||||
const formData = new FormData()
|
||||
formData.append('handle', handle)
|
||||
formData.append('action', action)
|
||||
|
||||
const response = await fetch(`${API_BASE}/manage`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || `Failed to ${action} module`)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user