diff --git a/AicsKnowledgeBase_file/Controllers/FileController.cs b/AicsKnowledgeBase_file/Controllers/FileController.cs index cb43b03..1c8bed2 100644 --- a/AicsKnowledgeBase_file/Controllers/FileController.cs +++ b/AicsKnowledgeBase_file/Controllers/FileController.cs @@ -19,9 +19,10 @@ public class FileController : ControllerBase { public async Task GetFileStatus(string fileId) { try { var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId); - var existingRanges = await _knowledgeFileHandler.GetAllPartFileRanges(fileId); + var existingRanges = (await _knowledgeFileHandler.GetAllPartFileRanges(fileId)) + .Select((range, _) => $"{range.Item1}-{range.Item2}"); - return Ok(new FileStatus(metadata.IsCompleted, metadata.Md5, metadata.Size, existingRanges)); + return Ok(new FileStatus(metadata.IsCompleted, metadata.Md5, metadata.Size, existingRanges.ToList())); } catch (FileNotFoundException) { return NotFound(); } @@ -83,5 +84,5 @@ internal record FileStatus( bool IsCompleted, string Md5, ulong Size, - List> ExistingRanges + List ExistingRanges ); \ No newline at end of file diff --git a/AicsKnowledgeBase_file/Handlers/KnowledgeFileHandler.cs b/AicsKnowledgeBase_file/Handlers/KnowledgeFileHandler.cs index 3c981e5..27c9381 100644 --- a/AicsKnowledgeBase_file/Handlers/KnowledgeFileHandler.cs +++ b/AicsKnowledgeBase_file/Handlers/KnowledgeFileHandler.cs @@ -20,11 +20,11 @@ public class KnowledgeFileHandler { } public async Task GetAllPartFiles(string fileId) { - return Directory.GetFiles($"{FilePath}/{fileId}.part.*"); + return Directory.GetFiles(FilePath, $"{fileId}.part.*"); } public Tuple ConvertPartFileNameToRange(string fileName) { - var range = fileName.Split('.')[2].Split('-'); + var range = fileName.Split('.').Last().Split('-'); return Tuple.Create(ulong.Parse(range[0]), ulong.Parse(range[1])); } @@ -43,7 +43,8 @@ public class KnowledgeFileHandler { } public async Task SaveFileSlice(string fileId, IFormFile file, ulong rangeStart, ulong rangeEnd) { - await file.CopyToAsync(File.Create(GetSliceFileName(fileId, rangeStart, rangeEnd))); + await using var fileStream = File.Create(GetSliceFileName(fileId, rangeStart, rangeEnd)); + await file.CopyToAsync(fileStream); } /// 缺失分片时抛出,其Message内容是缺失分片的Range