mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29: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 { MastodonAccount } from '@/entities/MastodonAccount.ts';
|
||||||
|
import { MastodonAttachment } from '@/entities/MastodonAttachment.ts';
|
||||||
import { PreviewCard } from '@/entities/PreviewCard.ts';
|
import { PreviewCard } from '@/entities/PreviewCard.ts';
|
||||||
|
|
||||||
export interface MastodonStatus {
|
export interface MastodonStatus {
|
||||||
|
|
@ -24,16 +25,7 @@ export interface MastodonStatus {
|
||||||
pinned: boolean;
|
pinned: boolean;
|
||||||
reblog: MastodonStatus | null;
|
reblog: MastodonStatus | null;
|
||||||
application: unknown;
|
application: unknown;
|
||||||
media_attachments: {
|
media_attachments: MastodonAttachment[];
|
||||||
type: string;
|
|
||||||
preview_url?: string;
|
|
||||||
meta?: {
|
|
||||||
original?: {
|
|
||||||
width?: number;
|
|
||||||
height?: number;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}[];
|
|
||||||
mentions: unknown[];
|
mentions: unknown[];
|
||||||
tags: unknown[];
|
tags: unknown[];
|
||||||
emojis: unknown[];
|
emojis: unknown[];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
import { MastodonAttachment } from '@/entities/MastodonAttachment.ts';
|
||||||
import { getUrlMediaType } from '@/utils/media.ts';
|
import { getUrlMediaType } from '@/utils/media.ts';
|
||||||
|
|
||||||
/** Render Mastodon media attachment. */
|
/** 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 { id, data: tags } = media;
|
||||||
|
|
||||||
const url = tags.find(([name]) => name === 'url')?.[1];
|
const url = tags.find(([name]) => name === 'url')?.[1];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { NostrEvent } from '@nostrify/nostrify';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
|
import { MastodonAttachment } from '@/entities/MastodonAttachment.ts';
|
||||||
import { MastodonMention } from '@/entities/MastodonMention.ts';
|
import { MastodonMention } from '@/entities/MastodonMention.ts';
|
||||||
import { MastodonStatus } from '@/entities/MastodonStatus.ts';
|
import { MastodonStatus } from '@/entities/MastodonStatus.ts';
|
||||||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
|
|
@ -119,7 +120,9 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
|
||||||
pinned: Boolean(pinEvent),
|
pinned: Boolean(pinEvent),
|
||||||
reblog: null,
|
reblog: null,
|
||||||
application: 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,
|
mentions,
|
||||||
tags: [],
|
tags: [],
|
||||||
emojis: renderEmojis(event),
|
emojis: renderEmojis(event),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue