refactor: replace nip96 with blossom

feat: blossom fallback image loader
This commit is contained in:
2025-05-06 17:24:41 +01:00
parent d4115e9073
commit 4e5feede23
16 changed files with 267 additions and 278 deletions

View File

@ -38,6 +38,7 @@ const enum EventKind {
SearchRelaysList = 10_007, // NIP-51
InterestsList = 10_015, // NIP-51
EmojisList = 10_030, // NIP-51
BlossomServerList = 10_063,
StorageServerList = 10_096, // NIP-96 server list
FollowSet = 30_000, // NIP-51

View File

@ -9,6 +9,9 @@ export function readNip94TagsFromIMeta(tag: Array<string>) {
}
export function nip94TagsToIMeta(meta: Nip94Tags) {
if (!meta.url) {
throw new Error("URL is required!");
}
const ret: Array<string> = ["imeta"];
const ifPush = (key: string, value?: string | number) => {
if (value) {

View File

@ -12,6 +12,7 @@ import {
import { NostrLink, validateNostrLink } from "./nostr-link";
import { splitByUrl } from "./utils";
import { IMeta } from "./nostr";
import { Nip94Tags, readNip94TagsFromIMeta } from ".";
export interface ParsedFragment {
type:
@ -254,33 +255,14 @@ function extractMarkdownCode(fragments: Fragment[]): (string | ParsedFragment)[]
}
export function parseIMeta(tags: Array<Array<string>>) {
let ret: Record<string, IMeta> | undefined;
let ret: Record<string, Nip94Tags> | undefined;
const imetaTags = tags.filter(a => a[0] === "imeta");
for (const imetaTag of imetaTags) {
ret ??= {};
let imeta: IMeta = {};
let url = "";
for (const t of imetaTag.slice(1)) {
const [k, v] = t.split(" ");
if (k === "url") {
url = v;
}
if (k === "dim") {
const [w, h] = v.split("x");
imeta.height = Number(h);
imeta.width = Number(w);
}
if (k === "blurhash") {
imeta.blurHash = v;
}
if (k === "x") {
imeta.sha256 = v;
}
if (k === "alt") {
imeta.alt = v;
}
const meta = readNip94TagsFromIMeta(imetaTag);
if (meta.url) {
ret ??= {};
ret[meta.url] = meta;
}
ret[url] = imeta;
}
return ret;
}