添加项目文件。
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
|
||||
using FileService.Domain.ValueObjects;
|
||||
|
||||
namespace FileService.Application.StorageContracts
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ProviderCode">储存提供商编号</param>
|
||||
/// <param name="Bucket">储存桶名称</param>
|
||||
/// <param name="ObjectKey">鉴权key</param>
|
||||
/// <param name="ContentType"></param>
|
||||
/// <param name="ContentLength"></param>
|
||||
/// <param name="Metadata"></param>
|
||||
public sealed record InitiateUploadCommand(
|
||||
string ProviderCode,
|
||||
string Bucket,
|
||||
string ObjectKey,
|
||||
string ContentType,
|
||||
long ContentLength,
|
||||
IReadOnlyDictionary<string, string>? Metadata = null);
|
||||
|
||||
public sealed record InitiateUploadResult(
|
||||
string UploadSessionId,
|
||||
StorageLocation Location);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ProviderCode"></param>
|
||||
/// <param name="Bucket"></param>
|
||||
/// <param name="ObjectKey"></param>
|
||||
/// <param name="UploadSessionId"></param>
|
||||
/// <param name="PartNumber"></param>
|
||||
/// <param name="ExpiresIn"></param>
|
||||
public sealed record GenerateUploadUrlCommand(
|
||||
string ProviderCode,
|
||||
string Bucket,
|
||||
string ObjectKey,
|
||||
string UploadSessionId,
|
||||
int? PartNumber,
|
||||
TimeSpan ExpiresIn);
|
||||
|
||||
public sealed record PresignedUrl(
|
||||
string Url,
|
||||
IReadOnlyDictionary<string, string> Headers,
|
||||
DateTimeOffset ExpiresAt);
|
||||
|
||||
public sealed record CompleteUploadCommand(
|
||||
string ProviderCode,
|
||||
string Bucket,
|
||||
string Region,
|
||||
string ObjectKey,
|
||||
string UploadSessionId,
|
||||
IReadOnlyList<UploadPart> Parts);
|
||||
|
||||
public sealed record UploadPart(
|
||||
int PartNumber,
|
||||
string ETag,
|
||||
long? Size = null,
|
||||
string? Checksum = null);
|
||||
|
||||
public sealed record CompleteUploadResult(
|
||||
StorageLocation Location,
|
||||
string? ETag,
|
||||
long Size,
|
||||
string? Checksum = null,
|
||||
string? VersionId = null);
|
||||
}
|
||||
@@ -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