Avoid logging an error when weakly referenced attachment is missing

This commit is contained in:
trevor-signal
2025-09-25 16:23:40 -04:00
committed by GitHub
parent 11498482a1
commit 7fde9a311f
2 changed files with 23 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ import { pipeline } from 'node:stream/promises';
import z from 'zod';
import GrowingFile from 'growing-file';
import lodash from 'lodash';
import { pathExists } from 'fs-extra';
import {
type DecryptAttachmentToSinkOptionsType,
@@ -611,6 +612,22 @@ export async function handleAttachmentRequest(req: Request): Promise<Response> {
return new Response('Access denied', { status: 401 });
}
// Some attachments have weak references (e.g. copied quotes) and we
// don't want to treat those attachments missing as an error
const weakReferenceParam = url.searchParams.get('weakReference');
if (weakReferenceParam != null) {
strictAssert(
disposition === 'attachment',
'Only attachments can have weak references'
);
const fileExists = await pathExists(path);
if (!fileExists) {
return new Response('Weakly referenced attachment does not exist', {
status: 404,
});
}
}
// Get attachment size to trim the padding
const sizeParam = url.searchParams.get('size');
let maybeSize: number | undefined;