repo_description: Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿
repo_topics: blockchain crypto dapp graphql hacktoberfest lens-protocol nextjs react social-media tailwindcss turborepo typescript vitest wagmi web3
code: import type { AnyMediaFragment, Maybe } from "@/indexer/generated";
  import type { AttachmentData } from "@/types/misc";
  import sanitizeDStorageUrl from "./sanitizeDStorageUrl";
  
  const getAttachmentsData = (
    attachments?: Maybe<AnyMediaFragment[]>
  ): AttachmentData[] => {
    if (!attachments) {
      return [];
    }
  
    return attachments.map((attachment) => {
      switch (attachment.__typename) {
        case "MediaImage":
          return {
            type: "Image",
            uri: sanitizeDStorageUrl(attachment.item)
          } satisfies AttachmentData;
        case "MediaVideo":
          return {
            coverUri: sanitizeDStorageUrl(attachment.cover),
            type: "Video",
            uri: sanitizeDStorageUrl(attachment.item)
          } satisfies AttachmentData;
        case "MediaAudio":
          return {
            artist: attachment.artist,
            coverUri: sanitizeDStorageUrl(attachment.cover),
            type: "Audio",
            uri: sanitizeDStorageUrl(attachment.item)
          } satisfies AttachmentData;
        default:
          return {} as AttachmentData;
      }
    });
  };
  
  export default getAttachmentsData;
  