mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add MastodonAttachment type
This commit is contained in:
parent
efc121a4ae
commit
313c37564c
4 changed files with 25 additions and 12 deletions
15
src/entities/MastodonAttachment.ts
Normal file
15
src/entities/MastodonAttachment.ts
Normal file
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -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[];
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue