Skip to content

Commit 0ea57b0

Browse files
committed
update lint and error
1 parent 9549670 commit 0ea57b0

File tree

2 files changed

+293
-82
lines changed

2 files changed

+293
-82
lines changed

src/state/queries/microcosm-fallback.ts

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1-
import {AtUri} from '@atproto/api'
2-
import type {AppBskyFeedPost, AppBskyActorProfile} from '@atproto/api'
3-
41
const SLINGSHOT_URL = 'https://slingshot.microcosm.blue'
52
const CONSTELLATION_URL = 'https://constellation.microcosm.blue'
63

74
export interface MicrocosmRecord {
8-
uri: string
9-
cid: string
10-
value: any
5+
uri: string
6+
cid: string
7+
value: any
118
}
129

1310
export interface ConstellationCounts {
14-
likeCount: number
15-
repostCount: number
16-
replyCount: number
17-
// might need a saves/bookmark counter
18-
// bookmarkCount: number
11+
likeCount: number
12+
repostCount: number
13+
replyCount: number
14+
// might need a saves/bookmark counter
15+
// bookmarkCount: number
1916
}
2017

2118
/**
2219
* Generic helper to fetch from Slingshot proxy
2320
*/
2421
async function fetchFromSlingshot<T>(
2522
endpoint: string,
26-
params: Record<string, string>
23+
params: Record<string, string>,
2724
): Promise<T | null> {
2825
try {
29-
const queryString = new URLSearchParams(
30-
Object.entries(params).map(([key, value]) => [key, encodeURIComponent(value)])
31-
).toString()
32-
26+
// URLSearchParams handles encoding automatically, no need for manual encodeURIComponent
27+
const queryString = new URLSearchParams(params).toString()
28+
3329
const res = await fetch(`${SLINGSHOT_URL}/xrpc/${endpoint}?${queryString}`)
3430
if (!res.ok) return null
3531
return await res.json()
@@ -48,11 +44,11 @@ async function fetchFromSlingshot<T>(
4844
* @see https://slingshot.microcosm.blue/ for full API documentation
4945
*/
5046
export async function fetchRecordViaSlingshot(
51-
atUri: string
47+
atUri: string,
5248
): Promise<MicrocosmRecord | null> {
5349
return fetchFromSlingshot<MicrocosmRecord>(
5450
'com.bad-example.repo.getUriRecord',
55-
{ at_uri: atUri }
51+
{at_uri: atUri},
5652
)
5753
}
5854

@@ -67,12 +63,11 @@ export async function fetchRecordViaSlingshot(
6763
* @see https://slingshot.microcosm.blue/ for full API documentation
6864
*/
6965
export async function resolveIdentityViaSlingshot(
70-
identifier: string
66+
identifier: string,
7167
): Promise<{did: string; handle: string; pds: string} | null> {
72-
return fetchFromSlingshot(
73-
'com.bad-example.identity.resolveMiniDoc',
74-
{ identifier }
75-
)
68+
return fetchFromSlingshot('com.bad-example.identity.resolveMiniDoc', {
69+
identifier,
70+
})
7671
}
7772

7873
/**
@@ -87,21 +82,24 @@ export async function resolveIdentityViaSlingshot(
8782
* @see https://constellation.microcosm.blue/ for more about Constellation
8883
*/
8984
export async function fetchConstellationCounts(
90-
atUri: string
85+
atUri: string,
9186
): Promise<ConstellationCounts> {
92-
try {
87+
try {
9388
const res = await fetch(
94-
`${CONSTELLATION_URL}/links/all?target=${encodeURIComponent(atUri)}`
89+
`${CONSTELLATION_URL}/links/all?target=${encodeURIComponent(atUri)}`,
9590
)
9691
if (!res.ok) throw new Error('Constellation fetch failed')
9792

9893
const data = await res.json()
9994
const links = data.links || {}
10095

10196
return {
102-
likeCount: links?.['app.bsky.feed.like']?.['.subject.uri']?.distinct_dids ?? 0,
103-
repostCount: links?.['app.bsky.feed.repost']?.['.subject.uri']?.distinct_dids ?? 0,
104-
replyCount: links?.['app.bsky.feed.post']?.['.reply.parent.uri']?.records ?? 0,
97+
likeCount:
98+
links?.['app.bsky.feed.like']?.['.subject.uri']?.distinct_dids ?? 0,
99+
repostCount:
100+
links?.['app.bsky.feed.repost']?.['.subject.uri']?.distinct_dids ?? 0,
101+
replyCount:
102+
links?.['app.bsky.feed.post']?.['.reply.parent.uri']?.records ?? 0,
105103
}
106104
} catch (e) {
107105
console.error('Constellation fetch failed:', e)
@@ -140,7 +138,7 @@ export function isAppViewError(error: any): boolean {
140138
*/
141139
export async function buildSyntheticProfileView(
142140
did: string,
143-
handle: string
141+
handle: string,
144142
): Promise<any> {
145143
const profileUri = `at://${did}/app.bsky.actor.profile/self`
146144
const record = await fetchRecordViaSlingshot(profileUri)
@@ -158,8 +156,8 @@ export async function buildSyntheticProfileView(
158156
? `https://cdn.bsky.app/img/banner/plain/${did}/${record.value.banner.ref.$link}@jpeg`
159157
: undefined,
160158
followersCount: undefined, // Not available from PDS or Constellation
161-
followsCount: undefined, // Not available from PDS or Constellation
162-
postsCount: undefined, // Not available from PDS or Constellation
159+
followsCount: undefined, // Not available from PDS or Constellation
160+
postsCount: undefined, // Not available from PDS or Constellation
163161
indexedAt: new Date().toISOString(),
164162
viewer: {},
165163
labels: [],
@@ -173,7 +171,7 @@ export async function buildSyntheticProfileView(
173171
export async function buildSyntheticPostView(
174172
atUri: string,
175173
authorDid: string,
176-
authorHandle: string
174+
authorHandle: string,
177175
): Promise<any> {
178176
const record = await fetchRecordViaSlingshot(atUri)
179177
if (!record) return null
@@ -216,7 +214,7 @@ export async function buildSyntheticPostView(
216214
export async function buildSyntheticFeedPage(
217215
did: string,
218216
pdsUrl: string,
219-
cursor?: string
217+
cursor?: string,
220218
): Promise<any> {
221219
try {
222220
const limit = 25
@@ -228,7 +226,10 @@ export async function buildSyntheticFeedPage(
228226
const res = await fetch(url)
229227

230228
if (!res.ok) {
231-
console.error('[Fallback] Failed to fetch author feed from PDS:', res.statusText)
229+
console.error(
230+
'[Fallback] Failed to fetch author feed from PDS:',
231+
res.statusText,
232+
)
232233
return null
233234
}
234235

@@ -240,7 +241,7 @@ export async function buildSyntheticFeedPage(
240241
const postView = await buildSyntheticPostView(
241242
record.uri,
242243
did,
243-
'' // Handle will be resolved in buildSyntheticPostView
244+
'', // Handle will be resolved in buildSyntheticPostView
244245
)
245246

246247
if (!postView) return null
@@ -251,7 +252,7 @@ export async function buildSyntheticFeedPage(
251252
post: postView,
252253
feedContext: undefined,
253254
}
254-
})
255+
}),
255256
)
256257

257258
// Filter out null results

0 commit comments

Comments
 (0)