mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
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:
commit
7d8e5e676c
2 changed files with 9 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ import { logi } from '@soapbox/logi';
|
||||||
import { JsonValue } from '@std/json';
|
import { JsonValue } from '@std/json';
|
||||||
import { LanguageCode } from 'iso-639-1';
|
import { LanguageCode } from 'iso-639-1';
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
|
import linkify from 'linkifyjs';
|
||||||
import { nip27 } from 'nostr-tools';
|
import { nip27 } from 'nostr-tools';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
|
@ -17,6 +18,7 @@ import { abortError } from '@/utils/abort.ts';
|
||||||
import { purifyEvent } from '@/utils/purify.ts';
|
import { purifyEvent } from '@/utils/purify.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { detectLanguage } from '@/utils/language.ts';
|
import { detectLanguage } from '@/utils/language.ts';
|
||||||
|
import { getMediaLinks } from '@/utils/note.ts';
|
||||||
|
|
||||||
/** Function to decide whether or not to index a tag. */
|
/** Function to decide whether or not to index a tag. */
|
||||||
type TagCondition = (opts: TagConditionOpts) => boolean;
|
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) {
|
if (imeta.length) {
|
||||||
ext.media = 'true';
|
ext.media = 'true';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ interface ParsedNoteContent {
|
||||||
|
|
||||||
/** Convert Nostr content to Mastodon API HTML. Also return parsed data. */
|
/** Convert Nostr content to Mastodon API HTML. Also return parsed data. */
|
||||||
function parseNoteContent(content: string, mentions: MastodonMention[]): ParsedNoteContent {
|
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 firstUrl = links.find(isNonMediaLink)?.href;
|
||||||
|
|
||||||
const result = linkifyStr(content, {
|
const result = linkifyStr(content, {
|
||||||
|
|
@ -123,11 +123,6 @@ function isNonMediaLink({ href }: Link): boolean {
|
||||||
return /^https?:\/\//.test(href) && !getUrlMediaType(href);
|
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. */
|
/** Get pubkey from decoded bech32 entity, or undefined if not applicable. */
|
||||||
function getDecodedPubkey(decoded: nip19.DecodeResult): string | undefined {
|
function getDecodedPubkey(decoded: nip19.DecodeResult): string | undefined {
|
||||||
switch (decoded.type) {
|
switch (decoded.type) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue