Fix text attachment MIME misclassification (#3628)

* Fix text file attachment detection

* Add file attachment extraction tests
This commit is contained in:
Frank Yang
2026-01-28 18:33:03 -08:00
committed by GitHub
parent a109b7f1a9
commit cb18ce7a85
4 changed files with 364 additions and 13 deletions

View File

@@ -310,7 +310,14 @@ export async function resolveMedia(
fetchImpl,
filePathHint: file.file_path,
});
const saved = await saveMediaBuffer(fetched.buffer, fetched.contentType, "inbound", maxBytes);
const originalName = fetched.fileName ?? file.file_path;
const saved = await saveMediaBuffer(
fetched.buffer,
fetched.contentType,
"inbound",
maxBytes,
originalName,
);
// Check sticker cache for existing description
const cached = sticker.file_unique_id ? getCachedSticker(sticker.file_unique_id) : null;
@@ -377,7 +384,14 @@ export async function resolveMedia(
fetchImpl,
filePathHint: file.file_path,
});
const saved = await saveMediaBuffer(fetched.buffer, fetched.contentType, "inbound", maxBytes);
const originalName = fetched.fileName ?? file.file_path;
const saved = await saveMediaBuffer(
fetched.buffer,
fetched.contentType,
"inbound",
maxBytes,
originalName,
);
let placeholder = "<media:document>";
if (msg.photo) placeholder = "<media:image>";
else if (msg.video) placeholder = "<media:video>";