Merge branch 'legacy-media' into 'main'

Enable media:true for legacy (non-imeta) URL attachments

See merge request soapbox-pub/ditto!652
This commit is contained in:
Alex Gleason 2025-02-12 19:23:15 +00:00
commit 7d8e5e676c
2 changed files with 9 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import { logi } from '@soapbox/logi';
import { JsonValue } from '@std/json';
import { LanguageCode } from 'iso-639-1';
import { Kysely } from 'kysely';
import linkify from 'linkifyjs';
import { nip27 } from 'nostr-tools';
import { z } from 'zod';
@ -17,6 +18,7 @@ import { abortError } from '@/utils/abort.ts';
import { purifyEvent } from '@/utils/purify.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { detectLanguage } from '@/utils/language.ts';
import { getMediaLinks } from '@/utils/note.ts';
/** Function to decide whether or not to index a tag. */
type TagCondition = (opts: TagConditionOpts) => boolean;
@ -97,6 +99,12 @@ class EventsDB extends NPostgres {
})
);
// quirks mode
if (!imeta.length && event.kind === 1) {
const links = linkify.find(event.content).filter(({ type }) => type === 'url');
imeta.push(...getMediaLinks(links));
}
if (imeta.length) {
ext.media = 'true';

View file

@ -22,7 +22,7 @@ interface ParsedNoteContent {
/** Convert Nostr content to Mastodon API HTML. Also return parsed data. */
function parseNoteContent(content: string, mentions: MastodonMention[]): ParsedNoteContent {
const links = linkify.find(content).filter(isLinkURL);
const links = linkify.find(content).filter(({ type }) => type === 'url');
const firstUrl = links.find(isNonMediaLink)?.href;
const result = linkifyStr(content, {
@ -123,11 +123,6 @@ function isNonMediaLink({ href }: Link): boolean {
return /^https?:\/\//.test(href) && !getUrlMediaType(href);
}
/** Ensures the Link is a URL so it can be parsed. */
function isLinkURL(link: Link): boolean {
return link.type === 'url';
}
/** Get pubkey from decoded bech32 entity, or undefined if not applicable. */
function getDecodedPubkey(decoded: nip19.DecodeResult): string | undefined {
switch (decoded.type) {