fix: complete接口无法使用的问题

master
ArgonarioD 2023-07-06 11:33:55 +08:00
parent 69cd60000e
commit 17e86eb214
3 changed files with 15 additions and 8 deletions

View File

@ -53,10 +53,10 @@ public class FileController : ControllerBase {
return Ok();
}
[HttpPost("complete/{ticket}")]
public async Task<IActionResult> FilePostComplete(string fileId, string ticket) {
[HttpPost("complete")]
public async Task<IActionResult> FilePostComplete(string fileId, [FromForm] CompleteFileDto dto) {
var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId);
if (metadata.Ticket != ticket) {
if (metadata.Ticket != dto.Ticket) {
return this.ProblemFromCode(ErrorCodes.TicketMismatch);
}
@ -80,6 +80,10 @@ public record UploadFileDto(
IFormFile File
);
public record CompleteFileDto(
string Ticket
);
internal record FileStatus(
bool IsCompleted,
string Md5,

View File

@ -38,8 +38,8 @@ public class KnowledgeFileHandler {
return $"{FilePath}/{fileId}.part.{rangeStart}-{rangeEnd}";
}
public string GetFileName(string fileId) {
return $"{FilePath}/{fileId}";
public string GetFileName(string fileId, string suffix) {
return $"{FilePath}/{fileId}.{suffix}";
}
public async Task SaveFileSlice(string fileId, IFormFile file, ulong rangeStart, ulong rangeEnd) {
@ -69,7 +69,7 @@ public class KnowledgeFileHandler {
}
}
var fileStream = File.Create($"{FilePath}/{fileId}");
var fileStream = File.Create(GetFileName(fileId, metadata.Suffix));
foreach (var slice in slices) {
var sliceStream = File.OpenRead(GetSliceFileName(fileId, slice.Item1, slice.Item2));
await sliceStream.CopyToAsync(fileStream);
@ -79,10 +79,13 @@ public class KnowledgeFileHandler {
}
fileStream.Close();
metadata.IsCompleted = true;
await SaveFileMetadata(fileId, metadata);
}
public async Task<Memory<byte>> ReadRanged(string fileId, ulong rangeStart, ulong rangeEnd) {
var fileStream = File.OpenRead($"{FilePath}/{fileId}");
var metadata = await GetFileMetadata(fileId);
var fileStream = File.OpenRead(GetFileName(fileId, metadata.Suffix));
var buffer = new Memory<byte>(new byte[rangeEnd - rangeStart]);
await fileStream.ReadExactlyAsync(buffer);
fileStream.Close();

View File

@ -29,7 +29,7 @@ public class TencentCosHandler {
public async Task UploadFile(string fileId, string fileSuffix) {
var uploadTask = new COSXMLUploadTask(_tencentCosOptions.Bucket, $"{fileId}.{fileSuffix}");
uploadTask.SetSrcPath(_knowledgeFileHandler.GetFileName(fileId));
uploadTask.SetSrcPath(_knowledgeFileHandler.GetFileName(fileId, fileSuffix));
await _transferManager.UploadAsync(uploadTask);
}
}