fix(files): read restored content on the first request
A restored message can retain its attachment key while replacing the content. Retire the stale local source only after validating the current room and plan, then use the existing receive path in the same call. The retained-copy regression no longer needs an initial failing read; all 45 retention controls pass.
This commit is contained in:
1 parent
82f684a167
commit
cef99882e5
2 files changed
+3
-7
No files matched your search
@@ -565,12 +565,8 @@ export class ChannelAttachments {
|
||||
if (this.messageRemoved(key)) throw new Error("attachment_unavailable");
|
||||
if (this.sessionId && !this.rooms.some(room => room.id === key.roomId && room.authorized)) throw new Error("room_unavailable");
|
||||
if (inlineImage?.original) return inlineImageFile(inlineImage, attachment.name);
|
||||
const source = this.sources.get(fileKeyString(key));
|
||||
if (source) {
|
||||
if (!sameContent(source.attachment, attachment)) { this.withdraw(source, true); throw new Error("attachment_unavailable"); }
|
||||
return source.file;
|
||||
}
|
||||
const id = fileKeyString(key);
|
||||
const id = fileKeyString(key), source = this.sources.get(id);
|
||||
if (source && sameContent(source.attachment, attachment)) return source.file;
|
||||
// Runtime initialization is shared; cancellation only retires this wait.
|
||||
let cancel!: () => void;
|
||||
const cancelled = new Promise<never>((_, reject) => {
|
||||
@@ -585,6 +581,7 @@ export class ChannelAttachments {
|
||||
const room = this.rooms.find(room => room.id === key.roomId);
|
||||
if (!this.current(runtime) || !room?.authorized) throw new Error("room_unavailable");
|
||||
if (!this.matchesPlan({ key, attachment })) throw new Error("attachment_unavailable");
|
||||
if (source && room.available) this.withdraw(source, true);
|
||||
let entry = this.sinks.get(id);
|
||||
if (entry && !sameContent(entry.attachment, attachment)) {
|
||||
void this.stopSink(entry, new Error("attachment_unavailable"));
|
||||
|
||||
@@ -612,7 +612,6 @@ test.each(["in progress", "completed without retention"])("restore replaces a re
|
||||
await expect(old).resolves.toBe("AAA");
|
||||
}
|
||||
update("restored");
|
||||
if (phase === "completed without retention") await expect(read(b)).rejects.toThrow("attachment_unavailable");
|
||||
const next = read(b), download = files.download(key, b);
|
||||
await vi.waitFor(() => expect(getFileHandle).toHaveBeenCalledTimes(2));
|
||||
if (phase === "in progress") await expect(old).rejects.toThrow("attachment_unavailable");
|
||||
|
||||
Reference in new issue
Block a user