feat: add badge for suspicious and spam users

This commit is contained in:
codytseng 2025-11-25 23:11:31 +08:00
parent 2b4f673df1
commit c84c479871
23 changed files with 185 additions and 22 deletions

View file

@ -0,0 +1,47 @@
import DataLoader from 'dataloader'
export interface TrustScoreData {
percentile: number
}
class TrustScoreService {
static instance: TrustScoreService
private trustScoreDataLoader = new DataLoader<string, TrustScoreData | null>(async (userIds) => {
return await Promise.all(
userIds.map(async (userId) => {
try {
const res = await fetch(`https://fayan.jumble.social/${userId}`)
if (!res.ok) {
if (res.status === 404) {
return { percentile: 0 }
}
return null
}
const data = await res.json()
if (typeof data.percentile === 'number') {
return { percentile: data.percentile }
}
return null
} catch {
return null
}
})
)
})
constructor() {
if (!TrustScoreService.instance) {
TrustScoreService.instance = this
}
return TrustScoreService.instance
}
async fetchTrustScore(userId: string): Promise<TrustScoreData | null> {
return await this.trustScoreDataLoader.load(userId)
}
}
const instance = new TrustScoreService()
export default instance