From b800161895bd915e7b1b58b0f71182f0bf795798 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Thu, 6 Jul 2023 02:57:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=BB=A5=E5=8F=8A=E6=96=87=E4=BB=B6=E5=88=86?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AicsKnowledgeBase_file/Controllers/FileController.cs | 7 ++++--- AicsKnowledgeBase_file/Handlers/KnowledgeFileHandler.cs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) 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