@@ -2,12 +2,17 @@ import _ from 'lodash';
22import type { AnnotationsWithGlobal , MediaAnnotatorConfig , MediaSample } from '@labelu/audio-annotator-react' ;
33
44import type { ParsedResult , SampleResponse } from '@/api/types' ;
5- import { MediaType } from '@/api/types' ;
5+ import { MediaType , SampleState } from '@/api/types' ;
66
77import { jsonParse } from './index' ;
88import { generateDefaultValues } from './generateGlobalToolDefaultValues' ;
99
10- export function convertMediaAnnotations ( mediaType : MediaType , result : ParsedResult , config : MediaAnnotatorConfig ) {
10+ export function convertMediaAnnotations (
11+ mediaType : MediaType ,
12+ result : ParsedResult ,
13+ config : MediaAnnotatorConfig ,
14+ state ?: SampleState ,
15+ ) {
1116 // annotation
1217 const pool = [
1318 [ 'segment' , MediaType . VIDEO === mediaType ? 'videoSegmentTool' : 'audioSegmentTool' ] ,
@@ -20,7 +25,7 @@ export function convertMediaAnnotations(mediaType: MediaType, result: ParsedResu
2025 . map ( ( [ type , key ] ) => {
2126 const items = _ . get ( result , [ key , 'result' ] , [ ] ) ;
2227
23- if ( ! items . length && ( type === 'tag' || type === 'text' ) ) {
28+ if ( ! items . length && ( type === 'tag' || type === 'text' ) && state !== SampleState . NEW ) {
2429 // 生成全局工具的默认值
2530 return [ type , generateDefaultValues ( config ?. [ type ] ) ] ;
2631 }
@@ -60,6 +65,6 @@ export function convertAudioAndVideoSample(
6065 url : [ MediaType . VIDEO , MediaType . AUDIO ] . includes ( mediaType as MediaType )
6166 ? sample . file . url . replace ( 'attachment' , 'partial' )
6267 : sample . file . url ,
63- data : convertMediaAnnotations ( mediaType ! , resultParsed , config ) ,
68+ data : convertMediaAnnotations ( mediaType ! , resultParsed , config , sample . state ) ,
6469 } ;
6570}
0 commit comments