fix: align backend APIs and upload flow
This commit is contained in:
@@ -5,8 +5,8 @@ namespace FileService.WebApi.Controllers.FileTask
|
||||
{
|
||||
public class CompleteTaskRequest
|
||||
{
|
||||
public string SessionId { get; set; }
|
||||
public List<UploadPart> Parts { get; set; }
|
||||
public string SessionId { get; set; } = string.Empty;
|
||||
public List<UploadPart> Parts { get; set; } = [];
|
||||
}
|
||||
|
||||
public class CompleteTaskRequestValidator : AbstractValidator<CompleteTaskRequest>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using FileService.Application.UploadFileTask;
|
||||
using FileService.Application.UploadFileTask;
|
||||
using FileService.Infrastructure;
|
||||
using IM.ASPNETCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -28,6 +28,8 @@ namespace FileService.WebApi.Controllers.FileTask
|
||||
var res = await service.InitTaskAsync(new UploadTaskInitCommand(
|
||||
UploaderId: Guid.Parse(userId),
|
||||
ConversationId: request.ConversationId,
|
||||
ChatType: request.ChatType,
|
||||
TargetId: request.TargetId,
|
||||
FileName: request.FileName,
|
||||
FileSize: request.FileSize,
|
||||
contentType: request.ContentType,
|
||||
@@ -44,6 +46,13 @@ namespace FileService.WebApi.Controllers.FileTask
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
[HttpGet("status")]
|
||||
public async Task<IActionResult> Status(Guid taskId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.GetStatusAsync(taskId, Guid.Parse(userId)));
|
||||
}
|
||||
|
||||
[HttpGet("Getuploadurl")]
|
||||
public async Task<IActionResult> GetUploadUrl(string sessionId, int partNum)
|
||||
{
|
||||
@@ -53,19 +62,20 @@ namespace FileService.WebApi.Controllers.FileTask
|
||||
}
|
||||
|
||||
[HttpPost("complete")]
|
||||
[UnitOfWork(typeof(FileDbContext))]
|
||||
public async Task<IActionResult> Complete([FromBody] CompleteTaskRequest request)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var res = await service.CompleteTaskAsync(new UploadTaskCompleteCommand(request.SessionId, Guid.Parse(userId), request.Parts));
|
||||
return Ok(res);
|
||||
return res.Succeeded ? Accepted(res) : Ok(res);
|
||||
}
|
||||
|
||||
[HttpPost("local/parts/upload")]
|
||||
public async Task<IActionResult> LocalUpload(string sessionId, int partNumber, IFormFile file)
|
||||
public async Task<IActionResult> LocalUpload([FromForm] string sessionId, [FromForm] int partNumber, IFormFile file)
|
||||
{
|
||||
//var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var stream = file.OpenReadStream();
|
||||
var res = await service.UploadPartAsync(new UploadPartCommand(stream, sessionId, partNumber, file.Length));
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
await using var stream = file.OpenReadStream();
|
||||
var res = await service.UploadPartAsync(new UploadPartCommand(stream, sessionId, partNumber, file.Length), Guid.Parse(userId));
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,30 @@ namespace FileService.WebApi.Controllers.FileTask
|
||||
public class FileTaskInitRequest
|
||||
{
|
||||
public Guid ConversationId { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string? ChatType { get; set; }
|
||||
public Guid? TargetId { get; set; }
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public long FileSize { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
public string CheckSum { get; set; }
|
||||
public string ContentType { get; set; } = string.Empty;
|
||||
public string CheckSum { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
public class FileTaskInitRequestValidator: AbstractValidator<FileTaskInitRequest>
|
||||
{
|
||||
|
||||
public FileTaskInitRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.FileName).NotEmpty().MaximumLength(255);
|
||||
RuleFor(x => x.FileSize).GreaterThan(0);
|
||||
RuleFor(x => x.ContentType).NotEmpty().MaximumLength(255);
|
||||
RuleFor(x => x.CheckSum).NotEmpty().MaximumLength(128);
|
||||
RuleFor(x => x.ChatType)
|
||||
.Must(value => string.IsNullOrWhiteSpace(value) ||
|
||||
value.Equals("PRIVATE", StringComparison.OrdinalIgnoreCase) ||
|
||||
value.Equals("GROUP", StringComparison.OrdinalIgnoreCase))
|
||||
.WithMessage("chatType 必须为 PRIVATE 或 GROUP");
|
||||
RuleFor(x => x.TargetId)
|
||||
.NotEmpty()
|
||||
.When(x => !string.IsNullOrWhiteSpace(x.ChatType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user