feat: 适配了新的upload_file消息格式
parent
8cf7ef4c52
commit
94e28b5725
|
@ -19,7 +19,7 @@ public class FileController : ControllerBase {
|
||||||
var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId);
|
var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId);
|
||||||
var existingRanges = await _knowledgeFileHandler.GetAllPartFileRanges(fileId);
|
var existingRanges = await _knowledgeFileHandler.GetAllPartFileRanges(fileId);
|
||||||
|
|
||||||
return Ok(new FileStatus(metadata.IsCompleted, metadata.Md5!, metadata.Size!.Value, existingRanges));
|
return Ok(new FileStatus(metadata.IsCompleted, metadata.Md5, metadata.Size, existingRanges));
|
||||||
} catch (FileNotFoundException) {
|
} catch (FileNotFoundException) {
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ public class FileController : ControllerBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("metadata")]
|
// [HttpPost("metadata")]
|
||||||
public async Task<IActionResult> PostFileMetadata(string fileId, [FromBody] ClientFileMetadata metadata) {
|
/*public async Task<IActionResult> PostFileMetadata(string fileId, [FromBody] ClientFileMetadata metadata) {
|
||||||
var currentData = await _knowledgeFileHandler.GetFileMetadata(fileId);
|
var currentData = await _knowledgeFileHandler.GetFileMetadata(fileId);
|
||||||
if (currentData.Ticket != metadata.Ticket) {
|
if (currentData.Ticket != metadata.Ticket) {
|
||||||
return this.ProblemFromCode(ErrorCodes.TicketMismatch);
|
return this.ProblemFromCode(ErrorCodes.TicketMismatch);
|
||||||
|
@ -54,7 +54,7 @@ public class FileController : ControllerBase {
|
||||||
currentData.Size = metadata.Size;
|
currentData.Size = metadata.Size;
|
||||||
await _knowledgeFileHandler.SaveFileMetadata(fileId, currentData);
|
await _knowledgeFileHandler.SaveFileMetadata(fileId, currentData);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> UploadFilePart(string fileId, [FromForm] UploadFileDto dto) {
|
public async Task<IActionResult> UploadFilePart(string fileId, [FromForm] UploadFileDto dto) {
|
||||||
|
@ -84,11 +84,11 @@ public class FileController : ControllerBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ClientFileMetadata(
|
/*public record ClientFileMetadata(
|
||||||
string Ticket,
|
string Ticket,
|
||||||
string Md5,
|
string Md5,
|
||||||
ulong Size
|
ulong Size
|
||||||
);
|
);*/
|
||||||
|
|
||||||
public record UploadFileDto(
|
public record UploadFileDto(
|
||||||
string Ticket,
|
string Ticket,
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class KnowledgeFileHandler {
|
||||||
var range = fileName.Split('.')[2].Split('-');
|
var range = fileName.Split('.')[2].Split('-');
|
||||||
return Tuple.Create(ulong.Parse(range[0]), ulong.Parse(range[1]));
|
return Tuple.Create(ulong.Parse(range[0]), ulong.Parse(range[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Tuple<ulong, ulong>>> GetAllPartFileRanges(string fileId) {
|
public async Task<List<Tuple<ulong, ulong>>> GetAllPartFileRanges(string fileId) {
|
||||||
var result = (await GetAllPartFiles(fileId)).Select(ConvertPartFileNameToRange).ToList();
|
var result = (await GetAllPartFiles(fileId)).Select(ConvertPartFileNameToRange).ToList();
|
||||||
result.Sort((a, b) => (int)(a.Item1 - b.Item1));
|
result.Sort((a, b) => (int)(a.Item1 - b.Item1));
|
||||||
|
@ -49,6 +49,7 @@ public class KnowledgeFileHandler {
|
||||||
if (slices.Count == 0) {
|
if (slices.Count == 0) {
|
||||||
throw new InvalidDataException($"0-{metadata.Size}");
|
throw new InvalidDataException($"0-{metadata.Size}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slices.First().Item1 != 0) {
|
if (slices.First().Item1 != 0) {
|
||||||
throw new InvalidDataException($"0-{slices.First().Item1}");
|
throw new InvalidDataException($"0-{slices.First().Item1}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,9 @@ public class UpdateFileMessageConsumerHandler : BackgroundService {
|
||||||
var msg = result.Message.Value!;
|
var msg = result.Message.Value!;
|
||||||
await _knowledgeFileHandler.SaveFileMetadata(msg.Id, new FileMetadata {
|
await _knowledgeFileHandler.SaveFileMetadata(msg.Id, new FileMetadata {
|
||||||
IsCompleted = false,
|
IsCompleted = false,
|
||||||
Ticket = msg.Ticket
|
Ticket = msg.Ticket,
|
||||||
|
Md5 = msg.Md5,
|
||||||
|
Size = msg.Size
|
||||||
});
|
});
|
||||||
} catch (ConsumeException e) {
|
} catch (ConsumeException e) {
|
||||||
_logger.LogError("Consume Exception: {Exception}", e);
|
_logger.LogError("Consume Exception: {Exception}", e);
|
||||||
|
@ -59,5 +61,7 @@ public class UpdateFileMessageConsumerHandler : BackgroundService {
|
||||||
|
|
||||||
public record FileTicket(
|
public record FileTicket(
|
||||||
[JsonProperty("ticket")] string Ticket,
|
[JsonProperty("ticket")] string Ticket,
|
||||||
[JsonProperty("id")] string Id
|
[JsonProperty("id")] string Id,
|
||||||
|
[JsonProperty("md5")] string Md5,
|
||||||
|
[JsonProperty("size")] ulong Size
|
||||||
);
|
);
|
|
@ -3,6 +3,6 @@
|
||||||
public class FileMetadata {
|
public class FileMetadata {
|
||||||
public bool IsCompleted { get; set; } = false;
|
public bool IsCompleted { get; set; } = false;
|
||||||
public string Ticket { get; set; } = null!;
|
public string Ticket { get; set; } = null!;
|
||||||
public string? Md5 { get; set; }
|
public string Md5 { get; set; } = null!;
|
||||||
public ulong? Size { get; set; }
|
public ulong Size { get; set; } = 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue