feat: support for video events
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { EMBEDDED_MENTION_REGEX, ExtendedKind } from '@/constants'
|
||||
import client from '@/services/client.service'
|
||||
import { TImageInfo } from '@/types'
|
||||
import { TImetaInfo } from '@/types'
|
||||
import { LRUCache } from 'lru-cache'
|
||||
import { Event, kinds, nip19 } from 'nostr-tools'
|
||||
import {
|
||||
getImageInfoFromImetaTag,
|
||||
getImetaInfoFromImetaTag,
|
||||
generateBech32IdFromATag,
|
||||
generateBech32IdFromETag,
|
||||
tagNameEquals
|
||||
@@ -171,15 +171,15 @@ export function getUsingClient(event: Event) {
|
||||
return event.tags.find(tagNameEquals('client'))?.[1]
|
||||
}
|
||||
|
||||
export function getImageInfosFromEvent(event: Event) {
|
||||
const images: TImageInfo[] = []
|
||||
export function getImetaInfosFromEvent(event: Event) {
|
||||
const imeta: TImetaInfo[] = []
|
||||
event.tags.forEach((tag) => {
|
||||
const imageInfo = getImageInfoFromImetaTag(tag, event.pubkey)
|
||||
const imageInfo = getImetaInfoFromImetaTag(tag, event.pubkey)
|
||||
if (imageInfo) {
|
||||
images.push(imageInfo)
|
||||
imeta.push(imageInfo)
|
||||
}
|
||||
})
|
||||
return images
|
||||
return imeta
|
||||
}
|
||||
|
||||
export function getEmbeddedNoteBech32Ids(event: Event) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TEmoji, TImageInfo } from '@/types'
|
||||
import { TEmoji, TImetaInfo } from '@/types'
|
||||
import { isBlurhashValid } from 'blurhash'
|
||||
import { nip19 } from 'nostr-tools'
|
||||
import { isValidPubkey } from './pubkey'
|
||||
@@ -46,19 +46,19 @@ export function generateBech32IdFromATag(tag: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getImageInfoFromImetaTag(tag: string[], pubkey?: string): TImageInfo | null {
|
||||
export function getImetaInfoFromImetaTag(tag: string[], pubkey?: string): TImetaInfo | null {
|
||||
if (tag[0] !== 'imeta') return null
|
||||
const urlItem = tag.find((item) => item.startsWith('url '))
|
||||
const url = urlItem?.slice(4)
|
||||
if (!url) return null
|
||||
|
||||
const image: TImageInfo = { url, pubkey }
|
||||
const imeta: TImetaInfo = { url, pubkey }
|
||||
const blurHashItem = tag.find((item) => item.startsWith('blurhash '))
|
||||
const blurHash = blurHashItem?.slice(9)
|
||||
if (blurHash) {
|
||||
const validRes = isBlurhashValid(blurHash)
|
||||
if (validRes.result) {
|
||||
image.blurHash = blurHash
|
||||
imeta.blurHash = blurHash
|
||||
}
|
||||
}
|
||||
const dimItem = tag.find((item) => item.startsWith('dim '))
|
||||
@@ -66,10 +66,10 @@ export function getImageInfoFromImetaTag(tag: string[], pubkey?: string): TImage
|
||||
if (dim) {
|
||||
const [width, height] = dim.split('x').map(Number)
|
||||
if (width && height) {
|
||||
image.dim = { width, height }
|
||||
imeta.dim = { width, height }
|
||||
}
|
||||
}
|
||||
return image
|
||||
return imeta
|
||||
}
|
||||
|
||||
export function getPubkeysFromPTags(tags: string[][]) {
|
||||
|
||||
Reference in New Issue
Block a user