Files
WebDrop/server/src/WebDrop.Core/Models.cs
T
justme c858bd2a09 feat(server)!: require a logged-in account for every channel request
Drop unauthenticated guests from channels: the allow_guests setting, the
/guests endpoints and the guest seat table are gone, and requests without an
account session get 401 account_required. Share links are unaffected.
Contract version is now 8.0.0.
2026-10-16 06:46:15 +08:00

112 lines
3.2 KiB
C#

namespace WebDrop.Core;
public sealed record Channel(
Id16 Id,
ChannelMode Mode,
ChannelSettings Settings,
byte[]? ReadHash,
byte[]? WriteHash,
byte[] OwnerHash,
long CreatedAt,
long ExpiresAt,
long LastSeq,
long CompactedThrough,
long Bytes,
string CreatorAccount,
byte[]? JoinPasswordHash = null,
byte[]? JoinPasswordSalt = null);
public sealed record Share(
Id16 Id,
ShareSettings Settings,
byte[] ReadHash,
byte[]? OwnerHash,
byte[]? CreatorEndpointHash,
long CreatedAt,
long ExpiresAt,
long? SealedAt,
Id16? ManifestItemId,
long Bytes,
string CreatorAccount)
{
public bool IsSealed => SealedAt is not null;
}
public sealed record ShareItem(
Id16 ShareId,
Id16 ItemId,
FrameFlags Flags,
long MaxDownloads,
long Downloads,
int FrameCount,
long MaxIndex,
long? FinalIndex,
long Bytes,
long CreatedAt,
long ExpiresAt,
long? CloseDeadline)
{
public bool IsGated => (Flags & FrameFlags.Gated) != 0;
public bool IsSnapshot => (Flags & FrameFlags.Snapshot) != 0;
public bool IsComplete => FinalIndex is { } f && FrameCount == f + 1;
}
public sealed record ShareFrame(
Id16 ShareId,
Id16 ItemId,
uint Index,
long AckSeq,
int Length,
byte[] Digest,
byte[]? Inline,
string? BlobKey);
public sealed record Item(
Id16 ChannelId,
Id16 ItemId,
byte[] AuthorHash,
FrameFlags Flags,
long MaxDownloads,
long Downloads,
int FrameCount,
long MaxIndex,
long? FinalIndex,
long Bytes,
long CreatedAt,
long ExpiresAt,
long? CloseDeadline,
string? AuthorAccount)
{
public bool IsGated => (Flags & FrameFlags.Gated) != 0;
public bool IsSnapshot => (Flags & FrameFlags.Snapshot) != 0;
public bool IsComplete => FinalIndex is { } f && FrameCount == f + 1;
}
public sealed record ChannelInvitation(Id16 ChannelId, string Username, string Payload, long CreatedAt);
public sealed record ChannelMember(string Username, string Role, long JoinedAt);
public sealed record ChannelKeyPackage(Id16 ChannelId, string Username, string Role, string Payload, long CreatedAt);
/// <summary>已存储的一帧(完整封装)。Inline 与 BlobKey 二选一。</summary>
public sealed record StoredFrame(
Id16 ChannelId,
Id16 ItemId,
uint Index,
long Seq,
int Length,
byte[] Digest,
byte[]? Inline,
string? BlobKey);
public sealed record LogEntry(long Seq, LogKind Kind, Id16 ItemId, uint FrameIndex, byte Aux, long CreatedAt);
/// <summary>一次请求验证通过后的身份。频道只接受已登录账号。</summary>
public sealed record Principal(Role Role, string AccountName)
{
/// <summary>受限下载的计数单位:按用户计(设备只是账号的属性)。</summary>
public byte[] GrantKey => System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes("webdrop/grant/v1/" + AccountName));
}
/// <summary>请求携带的凭据,尚未验证。</summary>
public sealed record Credentials(Role ClaimedRole, byte[]? Token, byte[] EndpointHash, string? AccountName = null, string? AccountDeviceId = null,
bool RequireSignedContent = false);