-
Notifications
You must be signed in to change notification settings - Fork 17
/
attachments.ts
41 lines (36 loc) · 934 Bytes
/
attachments.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { base64Decode } from "./encoding.ts";
interface baseAttachment {
contentType: string;
filename: string;
}
export type Attachment =
& (
| textAttachment
| base64Attachment
| arrayBufferLikeAttachment
)
& baseAttachment;
export type ResolvedAttachment =
& (
| textAttachment
| arrayBufferLikeAttachment
)
& baseAttachment;
type textAttachment = { encoding: "text"; content: string };
type base64Attachment = { encoding: "base64"; content: string };
type arrayBufferLikeAttachment = {
content: ArrayBufferLike | Uint8Array;
encoding: "binary";
};
export function resolveAttachment(attachment: Attachment): ResolvedAttachment {
if (attachment.encoding === "base64") {
return {
filename: attachment.filename,
contentType: attachment.contentType,
encoding: "binary",
content: base64Decode(attachment.content),
};
} else {
return attachment;
}
}