diff --git a/src/entities/MastodonAttachment.ts b/src/entities/MastodonAttachment.ts new file mode 100644 index 00000000..7660c913 --- /dev/null +++ b/src/entities/MastodonAttachment.ts @@ -0,0 +1,15 @@ +export interface MastodonAttachment { + id: string; + type: string; + url: string; + preview_url?: string; + remote_url?: string | null; + description?: string; + blurhash?: string | null; + meta?: { + original?: { + width?: number; + height?: number; + }; + }; +} diff --git a/src/entities/MastodonStatus.ts b/src/entities/MastodonStatus.ts index e446eb11..3bc15f55 100644 --- a/src/entities/MastodonStatus.ts +++ b/src/entities/MastodonStatus.ts @@ -1,4 +1,5 @@ import { MastodonAccount } from '@/entities/MastodonAccount.ts'; +import { MastodonAttachment } from '@/entities/MastodonAttachment.ts'; import { PreviewCard } from '@/entities/PreviewCard.ts'; export interface MastodonStatus { @@ -24,16 +25,7 @@ export interface MastodonStatus { pinned: boolean; reblog: MastodonStatus | null; application: unknown; - media_attachments: { - type: string; - preview_url?: string; - meta?: { - original?: { - width?: number; - height?: number; - }; - }; - }[]; + media_attachments: MastodonAttachment[]; mentions: unknown[]; tags: unknown[]; emojis: unknown[]; diff --git a/src/views/mastodon/attachments.ts b/src/views/mastodon/attachments.ts index 0be61cba..9320f604 100644 --- a/src/views/mastodon/attachments.ts +++ b/src/views/mastodon/attachments.ts @@ -1,7 +1,10 @@ +import { MastodonAttachment } from '@/entities/MastodonAttachment.ts'; import { getUrlMediaType } from '@/utils/media.ts'; /** Render Mastodon media attachment. */ -function renderAttachment(media: { id?: string; data: string[][] }) { +function renderAttachment( + media: { id?: string; data: string[][] }, +): (MastodonAttachment & { cid?: string }) | undefined { const { id, data: tags } = media; const url = tags.find(([name]) => name === 'url')?.[1]; diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index f5d8d5bb..d1c02f1e 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -2,6 +2,7 @@ import { NostrEvent } from '@nostrify/nostrify'; import { nip19 } from 'nostr-tools'; import { Conf } from '@/config.ts'; +import { MastodonAttachment } from '@/entities/MastodonAttachment.ts'; import { MastodonMention } from '@/entities/MastodonMention.ts'; import { MastodonStatus } from '@/entities/MastodonStatus.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; @@ -119,7 +120,9 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise< pinned: Boolean(pinEvent), reblog: null, application: null, - media_attachments: media.map((m) => renderAttachment({ data: m })).filter(Boolean), + media_attachments: media.map((m) => renderAttachment({ data: m })).filter((m): m is MastodonAttachment => + Boolean(m) + ), mentions, tags: [], emojis: renderEmojis(event),