fix: complete接口无法使用的问题
parent
69cd60000e
commit
17e86eb214
|
@ -53,10 +53,10 @@ public class FileController : ControllerBase {
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("complete/{ticket}")]
|
[HttpPost("complete")]
|
||||||
public async Task<IActionResult> FilePostComplete(string fileId, string ticket) {
|
public async Task<IActionResult> FilePostComplete(string fileId, [FromForm] CompleteFileDto dto) {
|
||||||
var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId);
|
var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId);
|
||||||
if (metadata.Ticket != ticket) {
|
if (metadata.Ticket != dto.Ticket) {
|
||||||
return this.ProblemFromCode(ErrorCodes.TicketMismatch);
|
return this.ProblemFromCode(ErrorCodes.TicketMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,10 @@ public record UploadFileDto(
|
||||||
IFormFile File
|
IFormFile File
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public record CompleteFileDto(
|
||||||
|
string Ticket
|
||||||
|
);
|
||||||
|
|
||||||
internal record FileStatus(
|
internal record FileStatus(
|
||||||
bool IsCompleted,
|
bool IsCompleted,
|
||||||
string Md5,
|
string Md5,
|
||||||
|
|
|
@ -38,8 +38,8 @@ public class KnowledgeFileHandler {
|
||||||
return $"{FilePath}/{fileId}.part.{rangeStart}-{rangeEnd}";
|
return $"{FilePath}/{fileId}.part.{rangeStart}-{rangeEnd}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFileName(string fileId) {
|
public string GetFileName(string fileId, string suffix) {
|
||||||
return $"{FilePath}/{fileId}";
|
return $"{FilePath}/{fileId}.{suffix}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveFileSlice(string fileId, IFormFile file, ulong rangeStart, ulong rangeEnd) {
|
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) {
|
foreach (var slice in slices) {
|
||||||
var sliceStream = File.OpenRead(GetSliceFileName(fileId, slice.Item1, slice.Item2));
|
var sliceStream = File.OpenRead(GetSliceFileName(fileId, slice.Item1, slice.Item2));
|
||||||
await sliceStream.CopyToAsync(fileStream);
|
await sliceStream.CopyToAsync(fileStream);
|
||||||
|
@ -79,10 +79,13 @@ public class KnowledgeFileHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
|
metadata.IsCompleted = true;
|
||||||
|
await SaveFileMetadata(fileId, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Memory<byte>> ReadRanged(string fileId, ulong rangeStart, ulong rangeEnd) {
|
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]);
|
var buffer = new Memory<byte>(new byte[rangeEnd - rangeStart]);
|
||||||
await fileStream.ReadExactlyAsync(buffer);
|
await fileStream.ReadExactlyAsync(buffer);
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class TencentCosHandler {
|
||||||
|
|
||||||
public async Task UploadFile(string fileId, string fileSuffix) {
|
public async Task UploadFile(string fileId, string fileSuffix) {
|
||||||
var uploadTask = new COSXMLUploadTask(_tencentCosOptions.Bucket, $"{fileId}.{fileSuffix}");
|
var uploadTask = new COSXMLUploadTask(_tencentCosOptions.Bucket, $"{fileId}.{fileSuffix}");
|
||||||
uploadTask.SetSrcPath(_knowledgeFileHandler.GetFileName(fileId));
|
uploadTask.SetSrcPath(_knowledgeFileHandler.GetFileName(fileId, fileSuffix));
|
||||||
await _transferManager.UploadAsync(uploadTask);
|
await _transferManager.UploadAsync(uploadTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue