HH-846 / HH-799: add task recovery and audit (#27)
This commit is contained in:
+18
-3
@@ -25,6 +25,8 @@ const resourcePaths = {
|
||||
drafts: '/phase-a/drafts',
|
||||
confirmations: '/phase-a/confirmations',
|
||||
tasks: '/phase-a/tasks',
|
||||
attempts: '/phase-a/attempts',
|
||||
audit: '/phase-a/audit',
|
||||
'network-exits': '/network-exits',
|
||||
}
|
||||
|
||||
@@ -32,10 +34,18 @@ export const dataProvider = {
|
||||
async getList(resource, params = {}) {
|
||||
const path = resourcePaths[resource]
|
||||
if (!path) return unsupported(resource, 'getList')
|
||||
const filterKeys = { drafts: ['account_id'], confirmations: ['draft_id'], tasks: ['account_id', 'draft_id'] }[resource] || []
|
||||
const filterKeys = {
|
||||
drafts: ['account_id'], confirmations: ['draft_id'], tasks: ['account_id', 'draft_id', 'state'],
|
||||
audit: ['account_id', 'task_id', 'attempt_id', 'browser_env_alias', 'network_exit_id', 'event_type', 'from', 'to'],
|
||||
}[resource] || []
|
||||
const query = new URLSearchParams(filterKeys.flatMap(key => params.filter?.[key] ? [[key, params.filter[key]]] : []))
|
||||
if (resource === 'audit') {
|
||||
query.set('page', params.pagination?.page || 1)
|
||||
query.set('page_size', params.pagination?.perPage || 25)
|
||||
}
|
||||
const records = await request(`${path}${query.size ? `?${query}` : ''}`)
|
||||
return { data: records.map(record => ({ ...record, id: record.id ?? record.alias ?? record.version ?? record.name })), total: records.length }
|
||||
const data = Array.isArray(records) ? records : records.data
|
||||
return { data: data.map(record => ({ ...record, id: record.id ?? record.alias ?? record.version ?? record.name })), total: records.total ?? data.length }
|
||||
},
|
||||
async create(resource, { data }) {
|
||||
const path = resourcePaths[resource]
|
||||
@@ -59,7 +69,7 @@ export const dataProvider = {
|
||||
},
|
||||
async getOne(resource, { id }) {
|
||||
const path = resourcePaths[resource]
|
||||
if (!path || !['accounts', 'network-exits', 'drafts', 'confirmations', 'tasks'].includes(resource)) return unsupported(resource, 'getOne')
|
||||
if (!path || !['accounts', 'network-exits', 'browsers', 'drafts', 'confirmations', 'tasks', 'attempts'].includes(resource)) return unsupported(resource, 'getOne')
|
||||
const record = await request(`${path}/${encodeURIComponent(id)}`)
|
||||
return { data: { ...record, id: record.id ?? id } }
|
||||
},
|
||||
@@ -99,6 +109,11 @@ export const dataProvider = {
|
||||
enqueueConfirmation(confirmationID) {
|
||||
return request('/phase-a/tasks', jsonOptions('POST', { confirmation_id: confirmationID }))
|
||||
},
|
||||
async taskAction(id, action, data) {
|
||||
if (!['verify', 'resume', 'finish', 'cancel'].includes(action)) throw new Error(`未知任务操作: ${action}`)
|
||||
const options = data ? jsonOptions('POST', data) : { method: 'POST' }
|
||||
await request(`/phase-a/tasks/${encodeURIComponent(id)}/${action}`, options)
|
||||
},
|
||||
async networkExitAction(id, action) {
|
||||
if (action !== 'check' && action !== 'disable') throw new Error(`未知网络出口操作: ${action}`)
|
||||
return request(`/network-exits/${encodeURIComponent(id)}/${action}`, { method: 'POST' })
|
||||
|
||||
Reference in New Issue
Block a user