feat: inline text file attachments from Discord

Download and inline content of .txt and other text-based file
attachments instead of showing just the filename placeholder.
Handles long copy-pastes that Discord auto-converts to .txt files.
Truncates at 8000 chars with a note.
This commit is contained in:
Eyejoker
2026-03-14 02:32:14 +09:00
parent 16ab231df4
commit ae1b37694e
2 changed files with 38 additions and 4 deletions

View File

@@ -504,6 +504,7 @@ describe('DiscordChannel', () => {
vi.fn().mockResolvedValue({
ok: true,
arrayBuffer: () => Promise.resolve(new ArrayBuffer(8)),
text: () => Promise.resolve('Hello from text file'),
}),
);
});
@@ -637,7 +638,15 @@ describe('DiscordChannel', () => {
url: 'https://cdn.example.com/a.png',
},
],
['att2', { name: 'b.txt', contentType: 'text/plain' }],
[
'att2',
{
id: 'att2',
name: 'b.txt',
contentType: 'text/plain',
url: 'https://cdn.example.com/b.txt',
},
],
]);
const msg = createMessage({
content: '',
@@ -650,7 +659,7 @@ describe('DiscordChannel', () => {
'dc:1234567890123456',
expect.objectContaining({
content: expect.stringMatching(
/^\[Image: .+\.png\]\n\[File: b\.txt\]$/,
/^\[Image: .+\.png\]\n\[File: b\.txt\]\nHello from text file$/,
),
}),
);