fix: 修复生成详情对象解析 (#72)
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
</template>
|
||||
<script>
|
||||
import { getGeneration, getGenerationMedia, listGenerations } from '@/api/chorus'
|
||||
import { contains, dataOf, formatTime } from '../shared'
|
||||
import { contains, dataOf, detailOf, formatTime } from '../shared'
|
||||
import { attemptPresentation, generationDetailSize, generationTiming, kindText, reconcileGenerationDetail } from './helpers'
|
||||
export default {
|
||||
name: 'ChorusGenerations',
|
||||
@@ -60,7 +60,8 @@ export default {
|
||||
this.revokeObjectURLs(); this.inputMedia = []; this.imageOutputs = []; this.textOutputs = []; this.detailError = ''
|
||||
this.selected = row; this.detailOpen = true; this.detailLoading = true
|
||||
try {
|
||||
const detail = dataOf(await getGeneration(row.id))
|
||||
const detail = detailOf(await getGeneration(row.id))
|
||||
if (!detail) throw new Error('详情响应格式无效')
|
||||
if (version !== this.detailVersion) return
|
||||
this.selected = detail
|
||||
this.inputMedia = (detail.inputs || []).map(item => ({ ...item, loading: true, error: '', preview_url: '' }))
|
||||
|
||||
@@ -2,6 +2,11 @@ export function dataOf(response) {
|
||||
return Array.isArray(response && response.data) ? response.data : []
|
||||
}
|
||||
|
||||
export function detailOf(response) {
|
||||
const data = response && response.data
|
||||
return data && typeof data === 'object' && !Array.isArray(data) ? data : null
|
||||
}
|
||||
|
||||
export function formatTime(value) {
|
||||
if (!value) return '-'
|
||||
const date = new Date(value)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { contains, dataOf, formatTime } from '@/views/chorus/shared'
|
||||
import { contains, dataOf, detailOf, formatTime } from '@/views/chorus/shared'
|
||||
|
||||
describe('Chorus admin shared helpers', () => {
|
||||
test('unwraps only list responses', () => {
|
||||
@@ -6,6 +6,12 @@ describe('Chorus admin shared helpers', () => {
|
||||
expect(dataOf({ data: { id: 1 } })).toEqual([])
|
||||
})
|
||||
|
||||
test('unwraps only detail object responses', () => {
|
||||
expect(detailOf({ data: { id: 1, outputs: [] }})).toEqual({ id: 1, outputs: [] })
|
||||
expect(detailOf({ data: [{ id: 1 }] })).toBeNull()
|
||||
expect(detailOf({ data: null })).toBeNull()
|
||||
})
|
||||
|
||||
test('filters case-insensitively and handles empty values', () => {
|
||||
expect(contains('Provider Alpha', 'alpha')).toBe(true)
|
||||
expect(contains(null, 'alpha')).toBe(false)
|
||||
|
||||
Reference in New Issue
Block a user