mirror of
https://github.com/hoornet/vega.git
synced 2026-06-08 06:01:57 -07:00
Fix Blossom image URLs with non-standard extensions (.jp etc.)
SHA-256 hash filenames from content-addressed storage (Blossom/NIP-96) now always treated as images regardless of extension. Also broaden IMAGE_EXTENSIONS to cover avif, bmp, tiff, jp2 and common variants.
This commit is contained in:
+4
-2
@@ -2,7 +2,9 @@ import { nip19 } from "@nostr-dev-kit/ndk";
|
||||
|
||||
// Regex patterns
|
||||
const URL_REGEX = /https?:\/\/[^\s<>"')\]]+/g;
|
||||
const IMAGE_EXTENSIONS = /\.(jpg|jpeg|png|gif|webp|svg)(\?[^\s]*)?$/i;
|
||||
const IMAGE_EXTENSIONS = /\.(jpg|jpeg|jpg2|jp2|jpe|png|gif|webp|svg|avif|bmp|tiff?)(\?[^\s]*)?$/i;
|
||||
// Blossom / NIP-96 content-addressed URLs: SHA-256 hash (64 hex) as filename, any extension
|
||||
const BLOSSOM_URL_REGEX = /\/[0-9a-f]{64}(\.[a-z0-9]{0,5})?$/i;
|
||||
const VIDEO_EXTENSIONS = /\.(mp4|webm|mov|ogg|m4v|avi)(\?[^\s]*)?$/i;
|
||||
const AUDIO_EXTENSIONS = /\.(mp3|wav|flac|aac|m4a|opus|ogg)(\?[^\s]*)?$/i;
|
||||
const YOUTUBE_REGEX = /(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
|
||||
@@ -37,7 +39,7 @@ export function parseContent(content: string): ContentSegment[] {
|
||||
// Clean trailing punctuation that's likely not part of the URL
|
||||
const cleaned = url.replace(/[.,;:!?)]+$/, "");
|
||||
|
||||
if (IMAGE_EXTENSIONS.test(cleaned)) {
|
||||
if (IMAGE_EXTENSIONS.test(cleaned) || BLOSSOM_URL_REGEX.test(cleaned)) {
|
||||
allMatches.push({
|
||||
index: match.index,
|
||||
length: cleaned.length,
|
||||
|
||||
Reference in New Issue
Block a user