File index

This commit is contained in:
2025-11-12 22:09:13 +08:00
parent ce715cd6b0
commit e2b2bdd262
19 changed files with 2189 additions and 62 deletions

View File

@@ -31,6 +31,7 @@ public class SnCloudFile : ModelBase, ICloudFile, IIdentifiedResource
public Guid? PoolId { get; set; }
[JsonIgnore] public SnFileBundle? Bundle { get; set; }
public Guid? BundleId { get; set; }
[JsonIgnore] public List<SnCloudFileIndex> FileIndexes { get; set; } = [];
/// <summary>
/// The field is set to true if the recycling job plans to delete the file.

View File

@@ -0,0 +1,30 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace DysonNetwork.Shared.Models;
[Index(nameof(Path), nameof(AccountId))]
public class SnCloudFileIndex : ModelBase
{
public Guid Id { get; init; } = Guid.NewGuid();
/// <summary>
/// The path of the file,
/// only store the parent folder.
/// With the trailing slash.
///
/// Like /hello/here/ not /hello/here/text.txt or /hello/here
/// Or the user home folder files, store as /
///
/// Besides, the folder name should be all query-safe, not contains % or
/// other special characters that will mess up the pgsql query
/// </summary>
[MaxLength(8192)]
public string Path { get; init; } = null!;
[MaxLength(32)] public string FileId { get; init; } = null!;
public SnCloudFile File { get; init; } = null!;
public Guid AccountId { get; init; }
[NotMapped] public SnAccount? Account { get; init; }
}

View File

@@ -185,58 +185,55 @@ public class SnWalletGift : ModelBase
}
}
// TODO: Uncomment once protobuf files are regenerated
/*
public Proto.Gift ToProtoValue() => new()
{
Id = Id.ToString(),
GifterId = GifterId.ToString(),
RecipientId = RecipientId?.ToString(),
GiftCode = GiftCode,
Message = Message,
SubscriptionIdentifier = SubscriptionIdentifier,
BasePrice = BasePrice.ToString(CultureInfo.InvariantCulture),
FinalPrice = FinalPrice.ToString(CultureInfo.InvariantCulture),
Status = (Proto.GiftStatus)Status,
RedeemedAt = RedeemedAt?.ToTimestamp(),
RedeemerId = RedeemerId?.ToString(),
SubscriptionId = SubscriptionId?.ToString(),
ExpiresAt = ExpiresAt.ToTimestamp(),
IsOpenGift = IsOpenGift,
PaymentMethod = PaymentMethod,
PaymentDetails = PaymentDetails.ToProtoValue(),
CouponId = CouponId?.ToString(),
Coupon = Coupon?.ToProtoValue(),
IsRedeemable = IsRedeemable,
IsExpired = IsExpired,
CreatedAt = CreatedAt.ToTimestamp(),
UpdatedAt = UpdatedAt.ToTimestamp()
};
public Proto.Gift ToProtoValue() => new()
{
Id = Id.ToString(),
GifterId = GifterId.ToString(),
RecipientId = RecipientId?.ToString(),
GiftCode = GiftCode,
Message = Message,
SubscriptionIdentifier = SubscriptionIdentifier,
BasePrice = BasePrice.ToString(CultureInfo.InvariantCulture),
FinalPrice = FinalPrice.ToString(CultureInfo.InvariantCulture),
Status = (Proto.GiftStatus)Status,
RedeemedAt = RedeemedAt?.ToTimestamp(),
RedeemerId = RedeemerId?.ToString(),
SubscriptionId = SubscriptionId?.ToString(),
ExpiresAt = ExpiresAt.ToTimestamp(),
IsOpenGift = IsOpenGift,
PaymentMethod = PaymentMethod,
PaymentDetails = PaymentDetails.ToProtoValue(),
CouponId = CouponId?.ToString(),
Coupon = Coupon?.ToProtoValue(),
IsRedeemable = IsRedeemable,
IsExpired = IsExpired,
CreatedAt = CreatedAt.ToTimestamp(),
UpdatedAt = UpdatedAt.ToTimestamp()
};
public static SnWalletGift FromProtoValue(Proto.Gift proto) => new()
{
Id = Guid.Parse(proto.Id),
GifterId = Guid.Parse(proto.GifterId),
RecipientId = proto.HasRecipientId ? Guid.Parse(proto.RecipientId) : null,
GiftCode = proto.GiftCode,
Message = proto.Message,
SubscriptionIdentifier = proto.SubscriptionIdentifier,
BasePrice = decimal.Parse(proto.BasePrice),
FinalPrice = decimal.Parse(proto.FinalPrice),
Status = (GiftStatus)proto.Status,
RedeemedAt = proto.RedeemedAt?.ToInstant(),
RedeemerId = proto.HasRedeemerId ? Guid.Parse(proto.RedeemerId) : null,
SubscriptionId = proto.HasSubscriptionId ? Guid.Parse(proto.SubscriptionId) : null,
ExpiresAt = proto.ExpiresAt.ToInstant(),
IsOpenGift = proto.IsOpenGift,
PaymentMethod = proto.PaymentMethod,
PaymentDetails = SnPaymentDetails.FromProtoValue(proto.PaymentDetails),
CouponId = proto.HasCouponId ? Guid.Parse(proto.CouponId) : null,
Coupon = proto.Coupon is not null ? SnWalletCoupon.FromProtoValue(proto.Coupon) : null,
CreatedAt = proto.CreatedAt.ToInstant(),
UpdatedAt = proto.UpdatedAt.ToInstant()
};
*/
public static SnWalletGift FromProtoValue(Proto.Gift proto) => new()
{
Id = Guid.Parse(proto.Id),
GifterId = Guid.Parse(proto.GifterId),
RecipientId = proto.HasRecipientId ? Guid.Parse(proto.RecipientId) : null,
GiftCode = proto.GiftCode,
Message = proto.Message,
SubscriptionIdentifier = proto.SubscriptionIdentifier,
BasePrice = decimal.Parse(proto.BasePrice),
FinalPrice = decimal.Parse(proto.FinalPrice),
Status = (GiftStatus)proto.Status,
RedeemedAt = proto.RedeemedAt?.ToInstant(),
RedeemerId = proto.HasRedeemerId ? Guid.Parse(proto.RedeemerId) : null,
SubscriptionId = proto.HasSubscriptionId ? Guid.Parse(proto.SubscriptionId) : null,
ExpiresAt = proto.ExpiresAt.ToInstant(),
IsOpenGift = proto.IsOpenGift,
PaymentMethod = proto.PaymentMethod,
PaymentDetails = SnPaymentDetails.FromProtoValue(proto.PaymentDetails),
CouponId = proto.HasCouponId ? Guid.Parse(proto.CouponId) : null,
Coupon = proto.Coupon is not null ? SnWalletCoupon.FromProtoValue(proto.Coupon) : null,
CreatedAt = proto.CreatedAt.ToInstant(),
UpdatedAt = proto.UpdatedAt.ToInstant()
};
}
public abstract class SubscriptionType