using FluentValidation; namespace FileService.WebApi.Controllers.FileTask { public class FileTaskInitRequest { public Guid ConversationId { 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; } = string.Empty; public string CheckSum { get; set; } = string.Empty; } public class FileTaskInitRequestValidator: AbstractValidator { 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)); } } }