feat: filter invalid pubkeys in the follow list
This commit is contained in:
@@ -42,6 +42,10 @@ export function userIdToPubkey(userId: string) {
|
|||||||
return userId
|
return userId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isValidPubkey(pubkey: string) {
|
||||||
|
return /^[0-9a-f]{64}$/.test(pubkey)
|
||||||
|
}
|
||||||
|
|
||||||
const pubkeyImageCache = new LRUCache<string, string>({ max: 1000 })
|
const pubkeyImageCache = new LRUCache<string, string>({ max: 1000 })
|
||||||
export function generateImageByPubkey(pubkey: string): string {
|
export function generateImageByPubkey(pubkey: string): string {
|
||||||
if (pubkeyImageCache.has(pubkey)) {
|
if (pubkeyImageCache.has(pubkey)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { TImageInfo } from '@/types'
|
import { TImageInfo } from '@/types'
|
||||||
import { isBlurhashValid } from 'blurhash'
|
import { isBlurhashValid } from 'blurhash'
|
||||||
|
import { isValidPubkey } from './pubkey'
|
||||||
|
|
||||||
export function tagNameEquals(tagName: string) {
|
export function tagNameEquals(tagName: string) {
|
||||||
return (tag: string[]) => tag[0] === tagName
|
return (tag: string[]) => tag[0] === tagName
|
||||||
@@ -49,7 +50,7 @@ export function extractPubkeysFromEventTags(tags: string[][]) {
|
|||||||
tags
|
tags
|
||||||
.filter(tagNameEquals('p'))
|
.filter(tagNameEquals('p'))
|
||||||
.map(([, pubkey]) => pubkey)
|
.map(([, pubkey]) => pubkey)
|
||||||
.filter(Boolean)
|
.filter((pubkey) => !!pubkey && isValidPubkey(pubkey))
|
||||||
.reverse()
|
.reverse()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user