this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add temp fix for blobref validation issue (#23)

authored by

devin ivy and committed by
GitHub
9395b182 8d5c1b11

+22 -1
+22 -1
src/util/subscription.ts
··· 1 1 import { Subscription } from '@atproto/xrpc-server' 2 2 import { cborToLexRecord, readCar } from '@atproto/repo' 3 + import { BlobRef } from '@atproto/lexicon' 3 4 import { ids, lexicons } from '../lexicon/lexicons' 4 5 import { Record as PostRecord } from '../lexicon/types/app/bsky/feed/post' 5 6 import { Record as RepostRecord } from '../lexicon/types/app/bsky/feed/repost' ··· 156 157 157 158 const isType = (obj: unknown, nsid: string) => { 158 159 try { 159 - lexicons.assertValidRecord(nsid, obj) 160 + lexicons.assertValidRecord(nsid, fixBlobRefs(obj)) 160 161 return true 161 162 } catch (err) { 162 163 return false 163 164 } 164 165 } 166 + 167 + // @TODO right now record validation fails on BlobRefs 168 + // simply because multiple packages have their own copy 169 + // of the BlobRef class, causing instanceof checks to fail. 170 + // This is a temporary solution. 171 + const fixBlobRefs = (obj: unknown): unknown => { 172 + if (Array.isArray(obj)) { 173 + return obj.map(fixBlobRefs) 174 + } 175 + if (obj && typeof obj === 'object') { 176 + if (obj.constructor.name === 'BlobRef') { 177 + const blob = obj as BlobRef 178 + return new BlobRef(blob.ref, blob.mimeType, blob.size, blob.original) 179 + } 180 + return Object.entries(obj).reduce((acc, [key, val]) => { 181 + return Object.assign(acc, { [key]: fixBlobRefs(val) }) 182 + }, {} as Record<string, unknown>) 183 + } 184 + return obj 185 + }