Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import type { AnyMediaFragment, Maybe } from "@hey/indexer";
2import type { AttachmentData } from "@hey/types/misc";
3import sanitizeDStorageUrl from "./sanitizeDStorageUrl";
4
5const getAttachmentsData = (
6 attachments?: Maybe<AnyMediaFragment[]>
7): AttachmentData[] => {
8 if (!attachments) {
9 return [];
10 }
11
12 return attachments.map((attachment) => {
13 switch (attachment.__typename) {
14 case "MediaImage":
15 return {
16 type: "Image",
17 uri: sanitizeDStorageUrl(attachment.item)
18 } satisfies AttachmentData;
19 case "MediaVideo":
20 return {
21 coverUri: sanitizeDStorageUrl(attachment.cover),
22 type: "Video",
23 uri: sanitizeDStorageUrl(attachment.item)
24 } satisfies AttachmentData;
25 case "MediaAudio":
26 return {
27 artist: attachment.artist,
28 coverUri: sanitizeDStorageUrl(attachment.cover),
29 type: "Audio",
30 uri: sanitizeDStorageUrl(attachment.item)
31 } satisfies AttachmentData;
32 default:
33 return {} as AttachmentData;
34 }
35 });
36};
37
38export default getAttachmentsData;