From bc33f270d095cd583514fd38372c78ccfa635674 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Apr 2024 11:33:28 -0500 Subject: [PATCH 1/3] gitlab-ci: check types --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fdb188d..5cff577 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,10 @@ lint: stage: test script: deno lint +check: + stage: test + script: deno task check + test: stage: test script: deno task test From 57b022451723db127273f1bd3dade45a3fc62ac7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Apr 2024 11:34:21 -0500 Subject: [PATCH 2/3] renderReblog: fix types --- src/views/mastodon/statuses.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index 35f89c5..791263c 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -104,12 +104,14 @@ async function renderReblog(event: DittoEvent) { if (!event.author) return; const repostId = event.tags.find(([name]) => name === 'p')?.[1]; - event.repost = await getEvent(repostId, { kind: 1 }); + if (!repostId) return; + event.repost = await getEvent(repostId, { kind: 1 }); if (!event.repost) return; const reblog = await renderStatus(event.repost); reblog.reblogged = true; + return { id: event.id, account: await renderAccount(event.author), From 9bfed222da3e6ca6004661fb8e0f2a87fe8d9a09 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Apr 2024 11:38:59 -0500 Subject: [PATCH 3/3] unfurlCard: fix types --- src/utils/unfurl.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utils/unfurl.ts b/src/utils/unfurl.ts index 85638ed..da11e84 100644 --- a/src/utils/unfurl.ts +++ b/src/utils/unfurl.ts @@ -28,25 +28,27 @@ async function unfurlCard(url: string, signal: AbortSignal): Promise fetchWorker(url, { signal }), }); + const { oEmbed, title, description, canonical_url, open_graph } = result; + return { - type: result.oEmbed?.type || 'link', - url: result.canonical_url || url, - title: result.oEmbed?.title || result.title || '', - description: result.open_graph?.description || result.description || '', - author_name: result.oEmbed?.author_name || '', - author_url: result.oEmbed?.author_url || '', - provider_name: result.oEmbed?.provider_name || '', - provider_url: result.oEmbed?.provider_url || '', + type: oEmbed?.type || 'link', + url: canonical_url || url, + title: oEmbed?.title || title || '', + description: open_graph?.description || description || '', + author_name: oEmbed?.author_name || '', + author_url: oEmbed?.author_url || '', + provider_name: oEmbed?.provider_name || '', + provider_url: oEmbed?.provider_url || '', // @ts-expect-error `html` does in fact exist on oEmbed. - html: sanitizeHtml(result.oEmbed?.html || '', { + html: sanitizeHtml(oEmbed?.html || '', { allowedTags: ['iframe'], allowedAttributes: { iframe: ['width', 'height', 'src', 'frameborder', 'allowfullscreen'], }, }), - width: result.oEmbed?.width || 0, - height: result.oEmbed?.height || 0, - image: result.oEmbed?.thumbnails?.[0].url || result.open_graph?.images?.[0].url || null, + width: ((oEmbed && oEmbed.type !== 'link') ? oEmbed.width : 0) || 0, + height: ((oEmbed && oEmbed.type !== 'link') ? oEmbed.height : 0) || 0, + image: oEmbed?.thumbnails?.[0].url || open_graph?.images?.[0].url || null, embed_url: '', blurhash: null, };