HH-749: add CreatorHub react-admin frontend

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
2026-08-27 22:34:36 +08:00
co-authored by multica-agent
parent 7f32399d04
commit 45853f4bce
12 changed files with 3241 additions and 236 deletions
+49
View File
@@ -0,0 +1,49 @@
import { HttpError } from 'ra-core'
async function request(path = '', options) {
const response = await fetch(`/api/browsers${path}`, options)
if (!response.ok) {
const body = await response.json().catch(() => ({}))
throw new HttpError(body.error || `请求失败 (${response.status})`, response.status, body)
}
return response.status === 204 ? null : response.json()
}
const unsupported = operation => Promise.reject(new Error(`browsers 不支持 ${operation}`))
export const dataProvider = {
async getList(resource) {
if (resource !== 'browsers') return unsupported('getList')
const browsers = await request()
return {
data: browsers.map(browser => ({ ...browser, id: browser.id || browser.name })),
total: browsers.length,
}
},
async create(resource, { data }) {
if (resource !== 'browsers') return unsupported('create')
const created = await request('', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
return { data: { ...data, ...created, id: created.id || created.name } }
},
getOne: () => unsupported('getOne'),
getMany: () => unsupported('getMany'),
getManyReference: () => unsupported('getManyReference'),
update: () => unsupported('update'),
updateMany: () => unsupported('updateMany'),
delete: () => unsupported('delete'),
deleteMany: () => unsupported('deleteMany'),
async browserAction(name, action) {
const paths = {
start: [`/${encodeURIComponent(name)}/start`, 'POST'],
stop: [`/${encodeURIComponent(name)}/stop`, 'POST'],
recycle: [`/${encodeURIComponent(name)}`, 'DELETE'],
}
const target = paths[action]
if (!target) throw new Error(`未知运行环境操作: ${action}`)
await request(target[0], { method: target[1] })
},
}