40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import { hasRemoteConfig, resolveRuntimeMode } from '@/utils/runtime-config.js'
|
|
import { normalizeFeedbackPayload } from './feedback-contract.js'
|
|
import {
|
|
createRequestError,
|
|
requestStrict
|
|
} from './request-client.js'
|
|
|
|
export const feedbackApi = {
|
|
async submitFeedback(payload, requestOptions = {}) {
|
|
const feedback = normalizeFeedbackPayload(payload)
|
|
if (resolveRuntimeMode() !== 'remote') {
|
|
throw createRequestError('当前为本地预览模式,反馈未提交服务器', 'WRITE_UNAVAILABLE')
|
|
}
|
|
return requestStrict({
|
|
url: '/genealogy/app/feedback',
|
|
method: 'POST',
|
|
data: feedback
|
|
}, {
|
|
requireData: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
},
|
|
|
|
async getFeedback(requestOptions = {}) {
|
|
if (!hasRemoteConfig()) {
|
|
throw createRequestError('我的反馈读取需要真实服务,当前本地预览不会伪造结果', 'REMOTE_READ_REQUIRED')
|
|
}
|
|
const feedbackHistory = await requestStrict({
|
|
url: '/genealogy/app/feedback',
|
|
method: 'GET'
|
|
}, {
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
if (!Array.isArray(feedbackHistory)) {
|
|
throw createRequestError('我的反馈响应不是列表', 'LIST_RESPONSE_INVALID')
|
|
}
|
|
return feedbackHistory
|
|
}
|
|
}
|