Fix uploading (almost)

This commit is contained in:
Alex Gleason
2024-05-18 14:32:50 -05:00
parent 7d34b9401e
commit 611a94bdcf
6 changed files with 38 additions and 28 deletions

View File

@@ -4,16 +4,16 @@ import { UnattachedMedia } from '@/db/unattached-media.ts';
type DittoAttachment = TypeFest.SetOptional<UnattachedMedia, 'id' | 'pubkey' | 'uploaded_at'>;
function renderAttachment(media: DittoAttachment) {
const { id, data, url } = media;
function renderAttachment(tags: string[][]) {
const url = tags.find(([name]) => name === 'url')?.[1];
const m = data.find(([name]) => name === 'm')?.[1];
const alt = data.find(([name]) => name === 'alt')?.[1];
const cid = data.find(([name]) => name === 'cid')?.[1];
const blurhash = data.find(([name]) => name === 'blurhash')?.[1];
const m = tags.find(([name]) => name === 'm')?.[1];
const alt = tags.find(([name]) => name === 'alt')?.[1];
const cid = tags.find(([name]) => name === 'cid')?.[1];
const blurhash = tags.find(([name]) => name === 'blurhash')?.[1];
return {
id: id ?? url,
id: url,
type: getAttachmentType(m ?? ''),
url,
preview_url: url,

View File

@@ -10,7 +10,7 @@ import { nostrDate } from '@/utils.ts';
import { getMediaLinks, parseNoteContent } from '@/utils/note.ts';
import { unfurlCardCached } from '@/utils/unfurl.ts';
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
import { DittoAttachment, renderAttachment } from '@/views/mastodon/attachments.ts';
import { renderAttachment } from '@/views/mastodon/attachments.ts';
import { renderEmojis } from '@/views/mastodon/emojis.ts';
interface RenderStatusOpts {
@@ -78,16 +78,11 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
const mediaLinks = getMediaLinks(links);
const mediaTags: DittoAttachment[] = event.tags
const imeta: string[][][] = event.tags
.filter(([name]) => name === 'imeta')
.map(([_, ...entries]) => {
const data = entries.map((entry) => entry.split(' '));
const url = data.find(([name]) => name === 'url')?.[1];
return { url, data };
})
.filter((media): media is DittoAttachment => !!media.url);
.map(([_, ...entries]) => entries.map((entry) => entry.split(' ')));
const media = [...mediaLinks, ...mediaTags];
const media = [...mediaLinks, ...imeta];
return {
id: event.id,