11using System . Text . RegularExpressions ;
2+ using MaiChartManager . Controllers . Music ;
23using MaiChartManager . Services ;
34using Microsoft . AspNetCore . Mvc ;
45using SimaiSharp ;
@@ -11,7 +12,7 @@ namespace MaiChartManager.Controllers.Charts;
1112public class ImportChartController ( StaticSettings settings , ILogger < StaticSettings > logger ,
1213 MaidataImportService importService ) : ControllerBase
1314{
14- public record ImportChartCheckResult ( bool Accept , IEnumerable < ImportChartMessage > Errors , Dictionary < ShiftMethod , float > chartPaddings , bool IsDx , string ? Title , float first ) ;
15+ public record ImportChartCheckResult ( bool Accept , IEnumerable < ImportChartMessage > Errors , Dictionary < ShiftMethod , float > chartPaddings , bool IsDx , string ? Title , float first , CueConvertController . SetAudioPreviewRequest ? previewTime ) ;
1516
1617 [ HttpPost ]
1718 public ImportChartCheckResult ImportChartCheck ( IFormFile file , [ FromForm ] bool isReplacement = false )
@@ -99,7 +100,7 @@ public ImportChartCheckResult ImportChartCheck(IFormFile file, [FromForm] bool i
99100 {
100101 errors . Add ( new ImportChartMessage ( Locale . MusicNoCharts , MessageLevel . Fatal ) ) ;
101102 fatal = true ;
102- return new ImportChartCheckResult ( ! fatal , errors , new Dictionary < ShiftMethod , float > ( ) , false , title , 0 ) ;
103+ return new ImportChartCheckResult ( ! fatal , errors , new Dictionary < ShiftMethod , float > ( ) , false , title , 0 , null ) ;
103104 }
104105
105106 float . TryParse ( maiData . GetValueOrDefault ( "first" ) , out var first ) ;
@@ -142,14 +143,22 @@ public ImportChartCheckResult ImportChartCheck(IFormFile file, [FromForm] bool i
142143
143144 var chartPaddings = MaidataImportService . CalcChartPadding ( maiCharts , out _ ) ;
144145
145- return new ImportChartCheckResult ( ! fatal , errors , chartPaddings , isDx , title , first ) ;
146+ CueConvertController . SetAudioPreviewRequest ? previewTime = null ;
147+ if ( float . TryParse ( maiData . GetValueOrDefault ( "demo_seek" ) , out var demo_seek ) )
148+ {
149+ // 当只有demo_seek没有demo_len时,则把demo_len设为一个很大的数,表示preview直到音频结尾;SetAudioPreviewApi中会自动把实际的loopEnd限制到音频长度以内。
150+ if ( ! float . TryParse ( maiData . GetValueOrDefault ( "demo_len" ) , out var demo_len ) ) demo_len = 10000f ;
151+ previewTime = new CueConvertController . SetAudioPreviewRequest ( demo_seek , demo_seek + demo_len ) ;
152+ }
153+
154+ return new ImportChartCheckResult ( ! fatal , errors , chartPaddings , isDx , title , first , previewTime ) ;
146155 }
147156 catch ( Exception e )
148157 {
149158 logger . LogError ( e , "解析谱面失败(大)" ) ;
150159 errors . Add ( new ImportChartMessage ( Locale . ChartParseFailedGlobal , MessageLevel . Fatal ) ) ;
151160 fatal = true ;
152- return new ImportChartCheckResult ( ! fatal , errors , new Dictionary < ShiftMethod , float > ( ) , false , "" , 0 ) ;
161+ return new ImportChartCheckResult ( ! fatal , errors , new Dictionary < ShiftMethod , float > ( ) , false , "" , 0 , null ) ;
153162 }
154163 }
155164
0 commit comments