@@ -1357,6 +1357,58 @@ public ActionResult DeleteMusic([FromQuery] int id, [FromQuery] string assetDir)
13571357 return Ok ( ) ;
13581358 }
13591359
1360+ public record BatchDeleteResult ( int Id , string AssetDir , bool Ok , string ? Error ) ;
1361+
1362+ [ HttpPost ]
1363+ public ActionResult < List < BatchDeleteResult > > BatchDelete ( [ FromBody ] BatchMusicIdDto dto )
1364+ {
1365+ var scanner = scannerService . Scanner ;
1366+ if ( scanner == null ) return NotFound ( ) ;
1367+
1368+ var results = new List < BatchDeleteResult > ( ) ;
1369+ foreach ( var item in dto . Ids )
1370+ {
1371+ try
1372+ {
1373+ if ( item . AssetDir == "A000" )
1374+ {
1375+ results . Add ( new BatchDeleteResult ( item . Id , item . AssetDir , false , "不能删除 A000 的曲目" ) ) ;
1376+ continue ;
1377+ }
1378+
1379+ var music = FindMusic ( scanner , item . Id , item . AssetDir ) ;
1380+ if ( music == null )
1381+ {
1382+ results . Add ( new BatchDeleteResult ( item . Id , item . AssetDir , false , "曲目不存在" ) ) ;
1383+ continue ;
1384+ }
1385+
1386+ if ( Directory . Exists ( music . MusicDirectory ) )
1387+ Directory . Delete ( music . MusicDirectory , true ) ;
1388+
1389+ var optRoot = ResolveOptRoot ( item . AssetDir ) ;
1390+ if ( optRoot != null )
1391+ {
1392+ var cueDir = Path . Combine ( optRoot , "cueFile" , $ "cueFile{ item . Id : D6} ") ;
1393+ if ( Directory . Exists ( cueDir ) )
1394+ Directory . Delete ( cueDir , true ) ;
1395+ }
1396+
1397+ results . Add ( new BatchDeleteResult ( item . Id , item . AssetDir , true , null ) ) ;
1398+ }
1399+ catch ( Exception ex )
1400+ {
1401+ results . Add ( new BatchDeleteResult ( item . Id , item . AssetDir , false , ex . Message ) ) ;
1402+ }
1403+ }
1404+
1405+ var newScanner = new MusicScanner ( StaticSettings . GamePath ) ;
1406+ newScanner . ScanAll ( ) ;
1407+ StaticSettings . Scanner = newScanner ;
1408+
1409+ return Ok ( results ) ;
1410+ }
1411+
13601412 [ HttpPost ]
13611413 public ActionResult OpenExplorer ( [ FromQuery ] int id , [ FromQuery ] string assetDir )
13621414 {
0 commit comments