添加项目文件。
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Application.StorageContracts
|
||||
{
|
||||
public sealed class UploadRuntimeCache
|
||||
{
|
||||
public string TaskId { get; init; } = default!;
|
||||
|
||||
public string ProviderCode { get; init; } = default!;
|
||||
|
||||
public string UploadSessionId { get; init; } = default!;
|
||||
|
||||
public string Bucket { get; init; } = default!;
|
||||
|
||||
public string Region { get; init; } = default!;
|
||||
|
||||
public string ObjectKey { get; init; } = default!;
|
||||
|
||||
public long FileSize { get; init; }
|
||||
|
||||
public int TotalPartCount { get; init; }
|
||||
|
||||
public long UploadedBytes { get; private set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
|
||||
public DateTimeOffset ExpireAt { get; init; }
|
||||
|
||||
public Dictionary<int, UploadPart> Parts { get; init; } = new();
|
||||
|
||||
public void AddOrUpdatePart(UploadPart part)
|
||||
{
|
||||
Parts[part.PartNumber] = part;
|
||||
|
||||
UploadedBytes = Parts.Sum(x => x.Value.Size ?? 0);
|
||||
}
|
||||
|
||||
public bool IsCompleted()
|
||||
{
|
||||
return Parts.Count == TotalPartCount;
|
||||
}
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
public static UploadRuntimeCache? FromJson(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize<UploadRuntimeCache>(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user