feat: integrate client and server sharing workflows
This commit is contained in:
1 parent
42b93ae2d8
commit
7406e2fe37
101 files changed
+3153
-253
No files matched your search
@@ -324,6 +324,9 @@ public sealed class ChannelService(
|
||||
if (!store.Read(tx => tx.BlobKeyExists(blobKey))) blobs.Delete(blobKey);
|
||||
}
|
||||
|
||||
private static bool IsItemReadable(Item item, long now) =>
|
||||
item.ExpiresAt > now && (item.CloseDeadline is null || item.CloseDeadline > now);
|
||||
|
||||
// ───────────────────────── 读取 ─────────────────────────
|
||||
|
||||
public async Task<LogPage> ReadLogAsync(Id16 id, Credentials creds, long from, int limit, CancellationToken ct = default)
|
||||
@@ -338,16 +341,19 @@ public sealed class ChannelService(
|
||||
if (from > 0 && from < channel.CompactedThrough + 1)
|
||||
throw new WebDropException(ErrorCode.Gone, channel.CompactedThrough + 1);
|
||||
|
||||
long now = clock.NowMs;
|
||||
var list = new List<(long Seq, byte[]? Bytes, StoredFrame? Frame)>();
|
||||
foreach (var e in tx.ReadLog(id, from, limit))
|
||||
{
|
||||
switch (e.Kind)
|
||||
{
|
||||
case LogKind.Frame:
|
||||
if (tx.GetFrame(id, e.ItemId, e.FrameIndex) is { } f) list.Add((e.Seq, null, f));
|
||||
if (tx.GetItem(id, e.ItemId) is { } frameItem && IsItemReadable(frameItem, now)
|
||||
&& tx.GetFrame(id, e.ItemId, e.FrameIndex) is { } f)
|
||||
list.Add((e.Seq, null, f));
|
||||
break;
|
||||
case LogKind.Announce:
|
||||
if (tx.GetItem(id, e.ItemId) is { } it)
|
||||
if (tx.GetItem(id, e.ItemId) is { } it && IsItemReadable(it, now))
|
||||
list.Add((e.Seq, LogRecord.EncodeAnnounce(e.Seq, e.ItemId, it.Flags, it.CreatedAt), null));
|
||||
break;
|
||||
case LogKind.Tombstone:
|
||||
@@ -378,7 +384,10 @@ public sealed class ChannelService(
|
||||
var item = tx.GetItem(id, itemId) ?? throw new WebDropException(ErrorCode.NotFound);
|
||||
|
||||
long now = clock.NowMs;
|
||||
if (item.CloseDeadline is { } deadline && (fromIndex == 0 || now > deadline))
|
||||
if (item.ExpiresAt <= now) throw new WebDropException(ErrorCode.Gone);
|
||||
if (item.CloseDeadline is { } deadline && (fromIndex == 0 || now >= deadline))
|
||||
throw new WebDropException(ErrorCode.Gone);
|
||||
if (item.IsGated && fromIndex > 0 && !tx.HasDownloadGrant(id, itemId, principal.EndpointHash))
|
||||
throw new WebDropException(ErrorCode.Gone);
|
||||
|
||||
if (fromIndex == 0 && item.IsGated)
|
||||
@@ -391,6 +400,7 @@ public sealed class ChannelService(
|
||||
? now + limits.DownloadGraceSeconds * 1000L
|
||||
: item.CloseDeadline;
|
||||
tx.UpdateItem(item with { Downloads = downloads, CloseDeadline = closeAt });
|
||||
tx.AddDownloadGrant(id, itemId, principal.EndpointHash);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
@@ -406,7 +416,10 @@ public sealed class ChannelService(
|
||||
var (_, principal) = Authenticate(tx, id, creds, SeatRule.Required);
|
||||
if (!ChannelPolicy.CanRead(principal)) throw new WebDropException(ErrorCode.Forbidden);
|
||||
var item = tx.GetItem(id, itemId) ?? throw new WebDropException(ErrorCode.NotFound);
|
||||
if (item.CloseDeadline is { } d && clock.NowMs > d) throw new WebDropException(ErrorCode.Gone);
|
||||
if (item.ExpiresAt <= clock.NowMs) throw new WebDropException(ErrorCode.Gone);
|
||||
if (item.IsGated && !tx.HasDownloadGrant(id, itemId, principal.EndpointHash))
|
||||
throw new WebDropException(ErrorCode.Gone);
|
||||
if (item.CloseDeadline is { } d && clock.NowMs >= d) throw new WebDropException(ErrorCode.Gone);
|
||||
|
||||
var taken = new List<StoredFrame>();
|
||||
uint expected = fromIndex;
|
||||
|
||||
Reference in new issue
Block a user