Skip to content

Commit 0d7b03e

Browse files
committed
feat: Add mime type to attachments
1 parent e12312b commit 0d7b03e

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

projects/stream-chat-angular/src/lib/attachment.service.spec.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,27 @@ describe('AttachmentService', () => {
354354
service.addAttachment(customAttachment);
355355

356356
expect(service.mapToAttachments()).toEqual([
357-
{ fallback: 'flower.png', image_url: 'http://url/to/img', type: 'image' },
357+
{
358+
fallback: 'flower.png',
359+
image_url: 'http://url/to/img',
360+
type: 'image',
361+
mime_type: 'image/png',
362+
},
358363
{
359364
type: 'video',
360365
title: 'test.mp4',
361366
file_size: 22233332,
362367
asset_url: 'http://url/to/file',
363368
thumb_url: 'http://url/to/thumb',
369+
mime_type: 'video/mp4',
364370
},
365371
{
366372
title: 'note.txt',
367373
file_size: 3272969,
368374
asset_url: 'http://url/to/data',
369375
type: 'file',
370376
thumb_url: undefined,
377+
mime_type: 'plain/text',
371378
},
372379
{
373380
type: 'video',
@@ -380,31 +387,47 @@ describe('AttachmentService', () => {
380387

381388
it('should create attachmentUploads from attachments', () => {
382389
const attachments = [
383-
{ fallback: 'flower.png', image_url: 'http://url/to/img', type: 'image' },
390+
{
391+
fallback: 'flower.png',
392+
image_url: 'http://url/to/img',
393+
type: 'image',
394+
mime_type: undefined,
395+
},
384396
{
385397
title: 'note.txt',
386398
file_size: 3272969,
387399
asset_url: 'http://url/to/data',
388400
type: 'file',
401+
mime_type: undefined,
389402
},
390403
{
391404
title: 'cute.mov',
392405
file_size: 45367543,
393406
asset_url: 'http://url/to/video',
394407
type: 'video',
395408
thumb_url: 'http://url/to/poster',
409+
mime_type: 'video/mov',
396410
},
397411
{
398412
type: 'file',
399413
asset_url: 'url/to/my/file',
400414
title: 'my-file.pdf',
415+
mime_type: 'application/pdf',
401416
isCustomAttachment: true,
402417
},
403418
];
404-
const imageFile = { name: 'flower.png' };
405-
const dataFile = { name: 'note.txt', size: 3272969 };
406-
const videoFile = { name: 'cute.mov', size: 45367543 };
407-
const customFile = { name: 'my-file.pdf', size: undefined };
419+
const imageFile = { name: 'flower.png', type: undefined };
420+
const dataFile = { name: 'note.txt', size: 3272969, type: undefined };
421+
const videoFile = {
422+
name: 'cute.mov',
423+
size: 45367543,
424+
type: 'video/mov',
425+
};
426+
const customFile = {
427+
name: 'my-file.pdf',
428+
size: undefined,
429+
type: 'application/pdf',
430+
};
408431
const result = [
409432
{
410433
file: imageFile,
@@ -462,6 +485,7 @@ describe('AttachmentService', () => {
462485
asset_url: 'url/to/my/file',
463486
file_size: undefined,
464487
title: 'my-file.pdf',
488+
mime_type: undefined,
465489
};
466490

467491
const spy = jasmine.createSpy();
@@ -476,6 +500,7 @@ describe('AttachmentService', () => {
476500
file: {
477501
name: 'my-file.pdf',
478502
size: undefined,
503+
type: undefined,
479504
} as unknown as File,
480505
type: 'file',
481506
fromAttachment: { ...customAttachment, isCustomAttachment: true },

projects/stream-chat-angular/src/lib/attachment.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export class AttachmentService<
166166
if (r.fromAttachment) {
167167
return r.fromAttachment;
168168
} else {
169+
attachment.mime_type = r.file?.type;
169170
if (r.type === 'image') {
170171
attachment.fallback = r.file?.name;
171172
attachment.image_url = r.url;
@@ -197,6 +198,7 @@ export class AttachmentService<
197198
type: 'image',
198199
file: {
199200
name: attachment.fallback,
201+
type: attachment.mime_type,
200202
} as File,
201203
fromAttachment: attachment,
202204
});
@@ -207,6 +209,7 @@ export class AttachmentService<
207209
file: {
208210
name: attachment.title,
209211
size: attachment.file_size,
212+
type: attachment.mime_type,
210213
} as File,
211214
type: attachment.type,
212215
thumb_url: attachment.thumb_url,

0 commit comments

Comments
 (0)