fix: align backend APIs and upload flow

This commit is contained in:
2026-09-15 14:10:55 +08:00
parent 32177a7293
commit 53e6195938
149 changed files with 4791 additions and 435 deletions
+9 -1
View File
@@ -12,10 +12,14 @@ namespace FileService.Domain.Entities
public FileState State { get; private set; } = FileState.Uploaded;
public StorageLocation StorageLocation { get; private set; } = new StorageLocation();
public CheckSum CheckSum { get; private set; }
public Guid? SourceTaskId { get; private set; }
public string? ChatType { get; private set; }
public Guid? TargetId { get; private set; }
public bool IsPublic { get; private set; }
private UploadFile() { }
public UploadFile(Guid ownerId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum)
public UploadFile(Guid ownerId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum, Guid? sourceTaskId = null, string? chatType = null, Guid? targetId = null, bool isPublic = false)
{
OwnerId = ownerId;
FileName = fileName;
@@ -23,6 +27,10 @@ namespace FileService.Domain.Entities
ContentType = contentType;
StorageLocation = storageLocation ?? new StorageLocation();
CheckSum = checkSum;
SourceTaskId = sourceTaskId;
ChatType = chatType?.ToUpperInvariant();
TargetId = targetId;
IsPublic = isPublic;
State = FileState.Uploaded;
}
+25 -7
View File
@@ -1,4 +1,4 @@
using FileService.Domain.Events;
using FileService.Domain.Events;
using FileService.Domain.ValueObjects;
using IM.DomainCommons;
@@ -8,19 +8,25 @@ namespace FileService.Domain.Entities
{
public Guid UploaderId { get; private set; }
public Guid ConversationId { get; private set; }
public string? ChatType { get; private set; }
public Guid? TargetId { get; private set; }
public FileName FileName { get; private set; }
public long FileSize { get; private set; }
public ContentType ContentType { get; private set; }
public StorageLocation StorageLocation { get; private set; }
public UploadTaskState State { get; private set; }
public CheckSum CheckSum { get; private set; }
public Guid? ResultFileId { get; private set; }
public string? FailureReason { get; private set; }
private UploadTask() { }
public UploadTask(Guid uploaderId, Guid conversationId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum)
public UploadTask(Guid uploaderId, Guid conversationId, string? chatType, Guid? targetId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum)
{
UploaderId = uploaderId;
ConversationId = conversationId;
ChatType = chatType?.ToUpperInvariant();
TargetId = targetId;
FileName = fileName;
FileSize = fileSize;
ContentType = contentType;
@@ -28,21 +34,33 @@ namespace FileService.Domain.Entities
CheckSum = checkSum;
}
public void StartUpload()
public void StartUpload(StorageLocation? location = null)
{
State = UploadTaskState.Uploading;
if (location != null) StorageLocation = location; State = UploadTaskState.Uploading;
}
public void CompleteUpload(StorageLocation location)
public void StartMerging(StorageLocation location)
{
StorageLocation = location;
State = UploadTaskState.Merging;
FailureReason = null;
NotifyModified();
}
public void CompleteUpload(Guid fileId)
{
ResultFileId = fileId;
State = UploadTaskState.Completed;
FailureReason = null;
NotifyModified();
AddDomainEvent(new UploadTaskCompletedDomainEvent(this));
}
public void Fail()
public void Fail(string reason)
{
State = UploadTaskState.Failed;
FailureReason = reason.Length > 500 ? reason[..500] : reason;
NotifyModified();
}
}
}