feat: parse imeta
This commit is contained in:
@ -32,6 +32,7 @@ export * from "./pow-util";
|
||||
export * from "./query-optimizer";
|
||||
export * from "./encrypted";
|
||||
export * from "./outbox-model";
|
||||
export { parseIMeta } from "./utils";
|
||||
|
||||
export * from "./impl/nip4";
|
||||
export * from "./impl/nip44";
|
||||
|
@ -81,3 +81,13 @@ export interface FullRelaySettings {
|
||||
}
|
||||
|
||||
export type NotSignedNostrEvent = Omit<NostrEvent, "sig">;
|
||||
|
||||
export interface IMeta {
|
||||
magnet?: string;
|
||||
sha256?: string;
|
||||
blurHash?: string;
|
||||
height?: number;
|
||||
width?: number;
|
||||
alt?: string;
|
||||
fallback?: Array<string>;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { equalProp } from "@snort/shared";
|
||||
import { FlatReqFilter } from "./query-optimizer";
|
||||
import { NostrEvent, ReqFilter } from "./nostr";
|
||||
import { IMeta, NostrEvent, ReqFilter } from "./nostr";
|
||||
|
||||
export function findTag(e: NostrEvent, tag: string) {
|
||||
const maybeTag = e.tags.find(evTag => {
|
||||
@ -50,3 +50,35 @@ export function splitByUrl(str: string) {
|
||||
|
||||
return str.split(urlRegex);
|
||||
}
|
||||
|
||||
export function parseIMeta(tags: Array<Array<string>>) {
|
||||
let ret: Record<string, IMeta> | 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;
|
||||
}
|
||||
}
|
||||
ret[url] = imeta;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user